Skip to content

Commit

Permalink
ldb: sync DLIST_DEMOTE_SHORT() changes to include/dlinklist.h
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
  • Loading branch information
metze-samba authored and slowfranklin committed Oct 13, 2023
1 parent 4fe39d9 commit 7672a29
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ldb/include/dlinklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ do { \
DLIST_ADD_END(list, p); \
} while (0)

/*
* like DLIST_DEMOTE(), but optimized
* for short lists with 0, 1 or 2 elements
*/
#define DLIST_DEMOTE_SHORT(list, p) \
do { \
if ((list) == NULL) { \
/* no reason to demote, just add */ \
DLIST_ADD(list, p); \
} else if ((list)->prev == (p)) { \
/* optimize if p is last */ \
} else if ((list) == (p)) { \
/* optimize if p is first */ \
(list)->prev->next = (p); \
(list) = (p)->next; \
(p)->next = NULL; \
} else { \
DLIST_DEMOTE(list, p); \
} \
} while (0)

/*
concatenate two lists - putting all elements of the 2nd list at the
end of the first list.
Expand Down

0 comments on commit 7672a29

Please sign in to comment.