Skip to content

Commit

Permalink
utils/list: add list_splice
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Jun 6, 2024
1 parent f4f22d5 commit 7932525
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ static inline bool list_is_empty(const struct list_node *head) {
return head->prev == head;
}

/// Splice a list of nodes from `from` to into the beginning of list `to`.
static inline void list_splice(struct list_node *from, struct list_node *to) {
if (list_is_empty(from)) {
return;
}
__list_link(from->prev, to->next);
__list_link(to, from->next);
list_init_head(from);
}

/// Return true if `to_check` is the first node in list headed by `head`
static inline bool
list_node_is_first(const struct list_node *head, const struct list_node *to_check) {
Expand Down

0 comments on commit 7932525

Please sign in to comment.