summaryrefslogtreecommitdiffstats
path: root/firmware/common
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-01-07 07:14:43 -0500
committerMichael Sevakis <jethead71@rockbox.org>2017-01-07 21:14:32 -0500
commit077e20664c8a1982fda3b21a3fb58e16fac325c5 (patch)
tree0b3b8e5834422478ca7c7900ecdb3904e5bd3bf6 /firmware/common
parent5c6ccb43b55d70350869429da25e2b54b45086d3 (diff)
downloadrockbox-077e20664c8a1982fda3b21a3fb58e16fac325c5.tar.gz
rockbox-077e20664c8a1982fda3b21a3fb58e16fac325c5.tar.bz2
rockbox-077e20664c8a1982fda3b21a3fb58e16fac325c5.zip
Improve the implementation of a couple linked list routines.
ll_insert_next() and ll_remove_next() can be done more elegantly by adding a level of indirection to reference the 'next' pointer. Change-Id: If3ab2bc2a659b517c793749cfa9088938ae08d0d
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/linked_list.c49
1 files changed, 13 insertions, 36 deletions
diff --git a/firmware/common/linked_list.c b/firmware/common/linked_list.c
index 006caacc91..a5b3de3cf7 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;
}
}