X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Flist.h;h=e8a99ac8e008c3103eee2a45c00d2c8d5321714d;hb=8dd985351675c0d31f6a3f757727b92b71c711ff;hp=b98ce59ff77d6c6344f6147fe13214b022c7a863;hpb=c79b2e626c60a29f684bc389f07a712b59fa99cc;p=mesa.git diff --git a/src/util/list.h b/src/util/list.h index b98ce59ff77..e8a99ac8e00 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -71,12 +71,18 @@ static inline void list_addtail(struct list_head *item, struct list_head *list) list->prev = item; } +static inline bool list_empty(struct list_head *list); + static inline void list_replace(struct list_head *from, struct list_head *to) { - to->prev = from->prev; - to->next = from->next; - from->next->prev = to; - from->prev->next = to; + if (list_empty(from)) { + list_inithead(to); + } else { + to->prev = from->prev; + to->next = from->next; + from->next->prev = to; + from->prev->next = to; + } } static inline void list_del(struct list_head *item) @@ -99,6 +105,14 @@ static inline bool list_empty(struct list_head *list) return list->next == list; } +/** + * Returns whether the list has exactly one element. + */ +static inline bool list_is_singular(const struct list_head *list) +{ + return list->next != NULL && list->next->next == list; +} + static inline unsigned list_length(struct list_head *list) { struct list_head *node; @@ -108,6 +122,28 @@ static inline unsigned list_length(struct list_head *list) return length; } +static inline void list_splice(struct list_head *src, struct list_head *dst) +{ + if (list_empty(src)) + return; + + src->next->prev = dst; + src->prev->next = dst->next; + dst->next->prev = src->prev; + dst->next = src->next; +} + +static inline void list_splicetail(struct list_head *src, struct list_head *dst) +{ + if (list_empty(src)) + return; + + src->prev->next = dst; + src->next->prev = dst->prev; + dst->prev->next = src->next; + dst->prev = src->prev; +} + static inline void list_validate(struct list_head *list) { struct list_head *node;