tail call

This commit is contained in:
2025-12-31 09:19:39 -06:00
parent 41eb4bf6f7
commit e21cd4e70b
2 changed files with 389 additions and 2756 deletions

View File

@@ -28,6 +28,10 @@
#include <stddef.h> #include <stddef.h>
#endif #endif
#ifndef NDEBUG
#include <assert.h>
#endif
struct list_head { struct list_head {
struct list_head *prev; struct list_head *prev;
struct list_head *next; struct list_head *next;
@@ -82,6 +86,29 @@ static inline int list_empty(struct list_head *el)
return el->next == el; return el->next == el;
} }
/* Move all elements from 'src' to 'dst', leaving 'src' empty.
'dst' must be empty before this call. */
static inline void list_splice(struct list_head *dst, struct list_head *src)
{
#ifndef NDEBUG
assert(dst != src);
assert(list_empty(dst));
#endif
if (!list_empty(src)) {
struct list_head *first = src->next;
struct list_head *last = src->prev;
/* Link dst to src's elements */
dst->next = first;
dst->prev = last;
first->prev = dst;
last->next = dst;
/* Reinitialize src as empty */
init_list_head(src);
}
}
#define list_for_each(el, head) \ #define list_for_each(el, head) \
for(el = (head)->next; el != (head); el = el->next) for(el = (head)->next; el != (head); el = el->next)

File diff suppressed because it is too large Load Diff