]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
move most of the guts of ply_list_remove_node
authorRay Strode <rstrode@redhat.com>
Mon, 4 Jun 2007 20:09:35 +0000 (16:09 -0400)
committerRay Strode <rstrode@redhat.com>
Mon, 4 Jun 2007 20:09:35 +0000 (16:09 -0400)
to ply_list_unlink_node, and rewrite it to be
more readable.

src/ply-list.c

index 7bfd3809ed8221e8ae477bbb18e03869c6a11dfe..7a031bd8a4fd2411685473da765ed1feadadf7a6 100644 (file)
@@ -204,33 +204,50 @@ ply_list_remove_data (ply_list_t *list,
     ply_list_remove_node (list, node);
 }
 
-void 
-ply_list_remove_node (ply_list_t      *list,
+static void 
+ply_list_unlink_node (ply_list_t      *list,
                       ply_list_node_t *node)
 {
+  ply_list_node_t *node_before, *node_after;
+
+  assert (list != NULL);
+
   if (node == NULL)
     return;
 
-  if (node == list->first_node)
-    list->first_node = node->next;
+  assert (ply_list_find_node (list, node->data) == node);
 
-  if (node == list->last_node)
-    list->last_node = node->previous;
+  node_before = node->previous;
+  node_after = node->next;
 
-  if (node->previous != NULL)
-    {
-      node->previous->next = node->next;
-      node->previous = NULL;
-    }
+  if (node_before != NULL)
+    node_before->next = node_after;
 
-  if (node->next != NULL)
-    {
-      node->next->previous = node->previous;
-      node->next = NULL;
-    }
+  if (node_after != NULL)
+    node_after->previous = node_before;
+
+  if (list->first_node == node)
+    list->first_node = node_after;
+
+  if (list->last_node == node)
+    list->last_node = node_before;
+
+  node->previous = NULL;
+  node->next = NULL;
 
-  ply_list_node_free (node);
   list->number_of_nodes--;
+  assert (ply_list_find_node (list, node->data) != node);
+  assert (ply_list_find_node (list, node->data) == NULL);
+}
+
+void 
+ply_list_remove_node (ply_list_t      *list,
+                      ply_list_node_t *node)
+{
+  assert (ply_list_find_node (list, node->data) != NULL);
+  ply_list_unlink_node (list, node);
+  assert (ply_list_find_node (list, node->data) == NULL);
+  ply_list_node_free (node);
 }
 
 ply_list_node_t *