diff options
| -rw-r--r-- | firmware/common/linked_list.c | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/firmware/common/linked_list.c b/firmware/common/linked_list.c index 006caac..a5b3de3 100644 --- a/firmware/common/linked_list.c +++ b/firmware/common/linked_list.c @@ -60,26 +60,14 @@ void ll_init(struct ll_head *list) void ll_insert_next(struct ll_head *list, struct ll_node *node, struct ll_node *newnode) { - if (node == NULL) - { - node = list->head; - - newnode->next = node; - list->head = newnode; - - if (node == NULL) - list->tail = node; - } - else - { - struct ll_node *next = node->next; + struct ll_node **nodep = node != NULL ? &node->next : &list->head; + struct ll_node *next = *nodep; - newnode->next = next; - node->next = newnode; + newnode->next = next; + *nodep = newnode; - if (next == NULL) - list->tail = newnode; - } + if (next == NULL) + list->tail = newnode; } /** @@ -117,27 +105,16 @@ void ll_insert_last(struct ll_head *list, struct ll_node *node) */ void ll_remove_next(struct ll_head *list, struct ll_node *node) { - if (node == NULL) - { - node = list->head->next; - - list->head = node; + struct ll_node **nodep = node != NULL ? &node->next : &list->head; + struct ll_node *next = *nodep; - if (node == NULL) - list->tail = NULL; - } - else + if (next != NULL) { - struct ll_node *next = node->next; - - if (next != NULL) - { - next = next->next; - node->next = next; + next = next->next; + *nodep = next; - if (!next) - list->tail = node; - } + if (next == NULL) + list->tail = node; } } |