mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-21 15:48:34 +02:00
core: simplify NMDedupMultiIter by storing CList pointer
Let next and head pointers point to the CList value, instead of NMDedupMultiEntry.
This commit is contained in:
parent
2861c59116
commit
4057a31017
3 changed files with 33 additions and 60 deletions
|
|
@ -302,9 +302,9 @@ guint nm_dedup_multi_index_dirty_remove_idx (NMDedupMultiIndex *self,
|
|||
/*****************************************************************************/
|
||||
|
||||
typedef struct _NMDedupMultiIter {
|
||||
const NMDedupMultiHeadEntry *head;
|
||||
const CList *_head;
|
||||
const CList *_next;
|
||||
const NMDedupMultiEntry *current;
|
||||
const NMDedupMultiEntry *next;
|
||||
} NMDedupMultiIter;
|
||||
|
||||
static inline void
|
||||
|
|
@ -312,11 +312,14 @@ nm_dedup_multi_iter_init (NMDedupMultiIter *iter, const NMDedupMultiHeadEntry *h
|
|||
{
|
||||
g_return_if_fail (iter);
|
||||
|
||||
iter->head = head;
|
||||
if (head && !c_list_is_empty (&head->lst_entries_head)) {
|
||||
iter->_head = &head->lst_entries_head;
|
||||
iter->_next = head->lst_entries_head.next;
|
||||
} else {
|
||||
iter->_head = NULL;
|
||||
iter->_next = NULL;
|
||||
}
|
||||
iter->current = NULL;
|
||||
iter->next = head && !c_list_is_empty (&head->lst_entries_head)
|
||||
? c_list_entry (head->lst_entries_head.next, NMDedupMultiEntry, lst_entries)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
|
|
@ -324,42 +327,19 @@ nm_dedup_multi_iter_next (NMDedupMultiIter *iter)
|
|||
{
|
||||
g_return_val_if_fail (iter, FALSE);
|
||||
|
||||
if (!iter->next)
|
||||
if (!iter->_next)
|
||||
return FALSE;
|
||||
|
||||
/* we always look ahead for the @next. This way, the user
|
||||
/* we always look ahead for the next. This way, the user
|
||||
* may delete the current entry (but no other entries). */
|
||||
iter->current = iter->next;
|
||||
if (iter->next->lst_entries.next == &iter->head->lst_entries_head)
|
||||
iter->next = NULL;
|
||||
iter->current = c_list_entry (iter->_next, NMDedupMultiEntry, lst_entries);
|
||||
if (iter->_next->next == iter->_head)
|
||||
iter->_next = NULL;
|
||||
else
|
||||
iter->next = c_list_entry (iter->next->lst_entries.next, NMDedupMultiEntry, lst_entries);
|
||||
iter->_next = iter->_next->next;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_dedup_multi_iter_rewind (NMDedupMultiIter *iter)
|
||||
{
|
||||
/* rewind the iterator.
|
||||
*
|
||||
* In principle, you can always delete the current entry.
|
||||
* However, if you delete *all* current entries, the list
|
||||
* head becomes invalid too and rewinding will crash.
|
||||
*
|
||||
* So, either
|
||||
* - don't modify the list
|
||||
* - if you modify it:
|
||||
* - only delete the current entry, don't delete other entries.
|
||||
* - you may add more entries, however that may make iteration
|
||||
* confusing.
|
||||
* - you may rewind the iterator, but only if not all
|
||||
* entires were deleted.
|
||||
*
|
||||
* Use with care. */
|
||||
g_return_if_fail (iter);
|
||||
nm_dedup_multi_iter_init (iter, iter->head);
|
||||
}
|
||||
|
||||
#define nm_dedup_multi_iter_for_each(iter, head_entry) \
|
||||
for (nm_dedup_multi_iter_init ((iter), (head_entry)); \
|
||||
nm_dedup_multi_iter_next ((iter)); \
|
||||
|
|
|
|||
|
|
@ -612,7 +612,6 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i
|
|||
* routes have their route metrics explicitly set. */
|
||||
priv->route_metric = priv->has_gateway ? (gint64) lowest_metric : (gint64) -1;
|
||||
|
||||
nm_dedup_multi_iter_rewind (&iter);
|
||||
nmp_cache_iter_for_each (&iter, head_entry, &plobj) {
|
||||
const NMPlatformIP4Route *route = NMP_OBJECT_CAST_IP4_ROUTE (plobj);
|
||||
|
||||
|
|
@ -1396,6 +1395,7 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
NMIP4ConfigPrivate *dst_priv;
|
||||
const NMIP4ConfigPrivate *src_priv;
|
||||
NMDedupMultiIter ipconf_iter_src, ipconf_iter_dst;
|
||||
const NMDedupMultiHeadEntry *head_entry_src;
|
||||
|
||||
g_return_val_if_fail (src != NULL, FALSE);
|
||||
g_return_val_if_fail (dst != NULL, FALSE);
|
||||
|
|
@ -1438,7 +1438,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
}
|
||||
|
||||
/* addresses */
|
||||
nm_ip_config_iter_ip4_address_init (&ipconf_iter_src, src);
|
||||
head_entry_src = nm_ip4_config_lookup_addresses (src);
|
||||
nm_dedup_multi_iter_init (&ipconf_iter_src, head_entry_src);
|
||||
nm_ip_config_iter_ip4_address_init (&ipconf_iter_dst, dst);
|
||||
are_equal = TRUE;
|
||||
while (TRUE) {
|
||||
|
|
@ -1465,15 +1466,13 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
}
|
||||
}
|
||||
if (!are_equal) {
|
||||
const NMPlatformIP4Address *r_src;
|
||||
|
||||
has_minor_changes = TRUE;
|
||||
nm_dedup_multi_index_dirty_set_idx (dst_priv->multi_idx, &dst_priv->idx_ip4_addresses);
|
||||
nm_dedup_multi_iter_rewind (&ipconf_iter_src);
|
||||
while (nm_ip_config_iter_ip4_address_next (&ipconf_iter_src, &r_src)) {
|
||||
nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) {
|
||||
nm_dedup_multi_index_add (dst_priv->multi_idx,
|
||||
&dst_priv->idx_ip4_addresses,
|
||||
NMP_OBJECT_UP_CAST (r_src),
|
||||
ipconf_iter_src.current->obj,
|
||||
NM_DEDUP_MULTI_IDX_MODE_APPEND_FORCE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
|
@ -1482,7 +1481,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
}
|
||||
|
||||
/* routes */
|
||||
nm_ip_config_iter_ip4_route_init (&ipconf_iter_src, src);
|
||||
head_entry_src = nm_ip4_config_lookup_routes (src);
|
||||
nm_dedup_multi_iter_init (&ipconf_iter_src, head_entry_src);
|
||||
nm_ip_config_iter_ip4_route_init (&ipconf_iter_dst, dst);
|
||||
are_equal = TRUE;
|
||||
while (TRUE) {
|
||||
|
|
@ -1510,15 +1510,12 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev
|
|||
}
|
||||
}
|
||||
if (!are_equal) {
|
||||
const NMPlatformIP4Route *r_src;
|
||||
|
||||
has_minor_changes = TRUE;
|
||||
nm_dedup_multi_index_dirty_set_idx (dst_priv->multi_idx, &dst_priv->idx_ip4_routes);
|
||||
nm_dedup_multi_iter_rewind (&ipconf_iter_src);
|
||||
while (nm_ip_config_iter_ip4_route_next (&ipconf_iter_src, &r_src)) {
|
||||
nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) {
|
||||
nm_dedup_multi_index_add (dst_priv->multi_idx,
|
||||
&dst_priv->idx_ip4_routes,
|
||||
NMP_OBJECT_UP_CAST (r_src),
|
||||
ipconf_iter_src.current->obj,
|
||||
NM_DEDUP_MULTI_IDX_MODE_APPEND_FORCE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -462,7 +462,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i
|
|||
* routes have their route metrics explicitly set. */
|
||||
priv->route_metric = has_gateway ? (gint64) lowest_metric : (gint64) -1;
|
||||
|
||||
nm_dedup_multi_iter_rewind (&iter);
|
||||
nmp_cache_iter_for_each (&iter, head_entry, &plobj) {
|
||||
const NMPlatformIP6Route *route = NMP_OBJECT_CAST_IP6_ROUTE (plobj);
|
||||
|
||||
|
|
@ -1174,6 +1173,7 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
|
|||
NMIP6ConfigPrivate *dst_priv;
|
||||
const NMIP6ConfigPrivate *src_priv;
|
||||
NMDedupMultiIter ipconf_iter_src, ipconf_iter_dst;
|
||||
const NMDedupMultiHeadEntry *head_entry_src;
|
||||
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (src), FALSE);
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (dst), FALSE);
|
||||
|
|
@ -1212,7 +1212,8 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
|
|||
}
|
||||
|
||||
/* addresses */
|
||||
nm_ip_config_iter_ip6_address_init (&ipconf_iter_src, src);
|
||||
head_entry_src = nm_ip6_config_lookup_addresses (src);
|
||||
nm_dedup_multi_iter_init (&ipconf_iter_src, head_entry_src);
|
||||
nm_ip_config_iter_ip6_address_init (&ipconf_iter_dst, dst);
|
||||
are_equal = TRUE;
|
||||
while (TRUE) {
|
||||
|
|
@ -1241,15 +1242,12 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
|
|||
}
|
||||
}
|
||||
if (!are_equal) {
|
||||
const NMPlatformIP6Address *r_src;
|
||||
|
||||
has_minor_changes = TRUE;
|
||||
nm_dedup_multi_index_dirty_set_idx (dst_priv->multi_idx, &dst_priv->idx_ip6_addresses);
|
||||
nm_dedup_multi_iter_rewind (&ipconf_iter_src);
|
||||
while (nm_ip_config_iter_ip6_address_next (&ipconf_iter_src, &r_src)) {
|
||||
nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) {
|
||||
nm_dedup_multi_index_add (dst_priv->multi_idx,
|
||||
&dst_priv->idx_ip6_addresses,
|
||||
NMP_OBJECT_UP_CAST (r_src),
|
||||
ipconf_iter_src.current->obj,
|
||||
NM_DEDUP_MULTI_IDX_MODE_APPEND_FORCE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
|
@ -1258,7 +1256,8 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
|
|||
}
|
||||
|
||||
/* routes */
|
||||
nm_ip_config_iter_ip6_route_init (&ipconf_iter_src, src);
|
||||
head_entry_src = nm_ip6_config_lookup_routes (src);
|
||||
nm_dedup_multi_iter_init (&ipconf_iter_src, head_entry_src);
|
||||
nm_ip_config_iter_ip6_route_init (&ipconf_iter_dst, dst);
|
||||
are_equal = TRUE;
|
||||
while (TRUE) {
|
||||
|
|
@ -1286,15 +1285,12 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
|
|||
}
|
||||
}
|
||||
if (!are_equal) {
|
||||
const NMPlatformIP6Route *r_src;
|
||||
|
||||
has_minor_changes = TRUE;
|
||||
nm_dedup_multi_index_dirty_set_idx (dst_priv->multi_idx, &dst_priv->idx_ip6_routes);
|
||||
nm_dedup_multi_iter_rewind (&ipconf_iter_src);
|
||||
while (nm_ip_config_iter_ip6_route_next (&ipconf_iter_src, &r_src)) {
|
||||
nm_dedup_multi_iter_for_each (&ipconf_iter_src, head_entry_src) {
|
||||
nm_dedup_multi_index_add (dst_priv->multi_idx,
|
||||
&dst_priv->idx_ip6_routes,
|
||||
NMP_OBJECT_UP_CAST (r_src),
|
||||
ipconf_iter_src.current->obj,
|
||||
NM_DEDUP_MULTI_IDX_MODE_APPEND_FORCE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue