mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
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
This commit is contained in:
parent
5c6ccb43b5
commit
077e20664c
1 changed files with 14 additions and 37 deletions
|
|
@ -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;
|
||||
struct ll_node **nodep = node != NULL ? &node->next : &list->head;
|
||||
struct ll_node *next = *nodep;
|
||||
|
||||
newnode->next = node;
|
||||
list->head = newnode;
|
||||
newnode->next = next;
|
||||
*nodep = newnode;
|
||||
|
||||
if (node == NULL)
|
||||
list->tail = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct ll_node *next = node->next;
|
||||
|
||||
newnode->next = next;
|
||||
node->next = 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)
|
||||
struct ll_node **nodep = node != NULL ? &node->next : &list->head;
|
||||
struct ll_node *next = *nodep;
|
||||
|
||||
if (next != NULL)
|
||||
{
|
||||
node = list->head->next;
|
||||
next = next->next;
|
||||
*nodep = next;
|
||||
|
||||
list->head = node;
|
||||
|
||||
if (node == NULL)
|
||||
list->tail = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct ll_node *next = node->next;
|
||||
|
||||
if (next != NULL)
|
||||
{
|
||||
next = next->next;
|
||||
node->next = next;
|
||||
|
||||
if (!next)
|
||||
list->tail = node;
|
||||
}
|
||||
if (next == NULL)
|
||||
list->tail = node;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue