1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

improves slist implementation (#29)

This commit is contained in:
Falk Werner
2019-04-26 20:50:57 +02:00
committed by GitHub
parent fa78e23533
commit 9130f00289
6 changed files with 153 additions and 64 deletions

View File

@@ -5,7 +5,7 @@
void wf_message_queue_cleanup(
struct wf_slist * queue)
{
struct wf_slist_item * item = queue->first;
struct wf_slist_item * item = wf_slist_first(queue);
while (NULL != item)
{
struct wf_slist_item * next = item->next;

View File

@@ -4,14 +4,20 @@
void wf_slist_init(
struct wf_slist * list)
{
list->first = NULL;
list->last = NULL;
list->head.next = NULL;
list->last = &list->head;
}
bool wf_slist_empty(
struct wf_slist * list)
{
return (NULL == list->first);
return (list->last == &list->head);
}
struct wf_slist_item * wf_slist_first(
struct wf_slist * list)
{
return list->head.next;
}
void wf_slist_append(
@@ -19,58 +25,36 @@ void wf_slist_append(
struct wf_slist_item * item)
{
item->next = NULL;
list->last->next = item;
list->last = item;
if (NULL != list->last)
if (NULL == list->head.next)
{
list->last->next = item;
list->last = item;
}
else
{
list->first = item;
list->last = item;
list->head.next = item;
}
}
struct wf_slist_item * wf_slist_remove_first(
struct wf_slist * list)
{
struct wf_slist_item * const result = list->first;
if (NULL != result)
{
list->first = list->first->next;
if (NULL == list->first)
{
list->last = NULL;
}
}
return result;
return wf_slist_remove_after(list, &list->head);
}
struct wf_slist_item * wf_slist_remove_after(
struct wf_slist * list,
struct wf_slist_item * prev)
{
struct wf_slist_item * result = NULL;
if (NULL != prev)
struct wf_slist_item * result = prev->next;
if (NULL != result)
{
result = prev->next;
if ((NULL != result) && (NULL != result->next))
{
prev->next = result->next;
}
else
prev->next = result->next;
if (list->last == result)
{
list->last = prev;
prev->next = NULL;
}
}
else
{
result = wf_slist_remove_first(list);
}
}
return result;

View File

@@ -17,7 +17,7 @@ struct wf_slist_item
struct wf_slist
{
struct wf_slist_item * first;
struct wf_slist_item head;
struct wf_slist_item * last;
};
@@ -27,6 +27,9 @@ extern void wf_slist_init(
extern bool wf_slist_empty(
struct wf_slist * list);
extern struct wf_slist_item * wf_slist_first(
struct wf_slist * list);
extern void wf_slist_append(
struct wf_slist * list,
struct wf_slist_item * item);