]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Lists: Replaced replace_node() by update_node() which is the only use of that function.
authorMaria Matejka <mq@ucw.cz>
Mon, 19 Aug 2019 12:36:51 +0000 (14:36 +0200)
committerMaria Matejka <mq@ucw.cz>
Fri, 1 May 2020 13:19:12 +0000 (15:19 +0200)
lib/lists.c
lib/lists_test.c
lib/resource.c

index 8553ee27ee0b5f5ac234d7eda862fa75c7166858..200576cf659c18153c9e7cc270943d00dc9138c2 100644 (file)
@@ -153,32 +153,20 @@ rem_node(node *n)
 }
 
 /**
- * replace_node - replace a node in a list with another one
- * @old: node to be removed
- * @new: node to be inserted
+ * update_node - update node after calling realloc on it
+ * @n: node to be updated
  *
- * Replaces node @old in the list it's linked in with node @new.  Node
- * @old may be a copy of the original node, which is not accessed
- * through the list. The function could be called with @old == @new,
- * which just fixes neighbors' pointers in the case that the node
- * was reallocated.
+ * Fixes neighbor pointers.
  */
 LIST_INLINE void
-replace_node(node *old, node *new)
+update_node(node *n)
 {
-  EXPENSIVE_CHECK(check_list(NULL, old));
+  ASSUME(n->next->prev == n->prev->next);
 
-  if (old != new)
-  {
-    ASSUME(new->prev == NULL);
-    ASSUME(new->next == NULL);
-  }
+  n->next->prev = n;
+  n->prev->next = n;
 
-  old->next->prev = new;
-  old->prev->next = new;
-
-  new->prev = old->prev;
-  new->next = old->next;
+  EXPENSIVE_CHECK(check_list(NULL, n));
 }
 
 /**
index f26a88e22d2f177a4c752b30595632247984c05f..cf0021febc24770a036337977b8c4249d31f44b2 100644 (file)
@@ -222,26 +222,29 @@ t_remove_node(void)
 }
 
 static int
-t_replace_node(void)
+t_update_node(void)
 {
   node head, inside, tail;
 
   init_list_();
   fill_list();
 
-  replace_node(&nodes[0], &head);
+  head = nodes[0];
+  update_node(&head);
   bt_assert(l.head == &head);
   bt_assert(head.prev == NODE &l.head);
   bt_assert(head.next == &nodes[1]);
   bt_assert(nodes[1].prev == &head);
 
-  replace_node(&nodes[MAX_NUM/2], &inside);
+  inside = nodes[MAX_NUM/2];
+  update_node(&inside);
   bt_assert(nodes[MAX_NUM/2-1].next == &inside);
   bt_assert(nodes[MAX_NUM/2+1].prev == &inside);
   bt_assert(inside.prev == &nodes[MAX_NUM/2-1]);
   bt_assert(inside.next == &nodes[MAX_NUM/2+1]);
 
-  replace_node(&nodes[MAX_NUM-1], &tail);
+  tail = nodes[MAX_NUM-1];
+  update_node(&tail);
   bt_assert(l.tail == &tail);
   bt_assert(tail.prev == &nodes[MAX_NUM-2]);
   bt_assert(tail.next == NODE &l.null);
@@ -280,7 +283,7 @@ main(int argc, char *argv[])
   bt_test_suite(t_add_head, "Adding nodes to head of list");
   bt_test_suite(t_insert_node, "Inserting nodes to list");
   bt_test_suite(t_remove_node, "Removing nodes from list");
-  bt_test_suite(t_replace_node, "Replacing nodes in list");
+  bt_test_suite(t_update_node, "Updating nodes in list");
   bt_test_suite(t_add_tail_list, "At the tail of a list adding the another list");
 
   return bt_exit_value();
index 7e6243212be673aa25aeecfc0049a22480d7b56c..5589373e01a5a160cdea3022a47955a7c73590f8 100644 (file)
@@ -388,7 +388,7 @@ mb_realloc(void *m, unsigned size)
   struct mblock *b = SKIP_BACK(struct mblock, data, m);
 
   b = xrealloc(b, sizeof(struct mblock) + size);
-  replace_node(&b->r.n, &b->r.n);
+  update_node(&b->r.n);
   b->size = size;
   return b->data;
 }