summaryrefslogtreecommitdiff
path: root/firmware
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
parent5c6ccb43b55d70350869429da25e2b54b45086d3 (diff)
downloadrockbox-077e20664c8a1982fda3b21a3fb58e16fac325c5.tar.gz
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')
-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)
60void ll_insert_next(struct ll_head *list, struct ll_node *node, 60void ll_insert_next(struct ll_head *list, struct ll_node *node,
61 struct ll_node *newnode) 61 struct ll_node *newnode)
62{ 62{
63 if (node == NULL) 63 struct ll_node **nodep = node != NULL ? &node->next : &list->head;
64 { 64 struct ll_node *next = *nodep;
65 node = list->head;
66
67 newnode->next = node;
68 list->head = newnode;
69
70 if (node == NULL)
71 list->tail = node;
72 }
73 else
74 {
75 struct ll_node *next = node->next;
76 65
77 newnode->next = next; 66 newnode->next = next;
78 node->next = newnode; 67 *nodep = newnode;
79 68
80 if (next == NULL) 69 if (next == NULL)
81 list->tail = newnode; 70 list->tail = newnode;
82 }
83} 71}
84 72
85/** 73/**
@@ -117,27 +105,16 @@ void ll_insert_last(struct ll_head *list, struct ll_node *node)
117 */ 105 */
118void ll_remove_next(struct ll_head *list, struct ll_node *node) 106void ll_remove_next(struct ll_head *list, struct ll_node *node)
119{ 107{
120 if (node == NULL) 108 struct ll_node **nodep = node != NULL ? &node->next : &list->head;
121 { 109 struct ll_node *next = *nodep;
122 node = list->head->next;
123
124 list->head = node;
125 110
126 if (node == NULL) 111 if (next != NULL)
127 list->tail = NULL;
128 }
129 else
130 { 112 {
131 struct ll_node *next = node->next; 113 next = next->next;
132 114 *nodep = next;
133 if (next != NULL)
134 {
135 next = next->next;
136 node->next = next;
137 115
138 if (!next) 116 if (next == NULL)
139 list->tail = node; 117 list->tail = node;
140 }
141 } 118 }
142} 119}
143 120