From: Ray Strode Date: Mon, 4 Jun 2007 20:09:35 +0000 (-0400) Subject: move most of the guts of ply_list_remove_node X-Git-Tag: 0.1.0~225 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cad0aea0a66ffe6201b9082cce8c7750ecdfa85;p=thirdparty%2Fplymouth.git move most of the guts of ply_list_remove_node to ply_list_unlink_node, and rewrite it to be more readable. --- diff --git a/src/ply-list.c b/src/ply-list.c index 7bfd3809..7a031bd8 100644 --- a/src/ply-list.c +++ b/src/ply-list.c @@ -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 *