mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
tevent: introduce DLIST_DEMOTE_SHORT()
It turns out that the overhead of DLIST_DEMOTE() implemented as DLIST_REMOVE();DLIST_ADD_END(), is very high if the list contains only 1 or 2 elements. The next commits will make use of DLIST_DEMOTE_SHORT() for multiplexing multiple tevent_fd structures for a single fd and the most important and common case is a list with just one element. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
d895c98c50
commit
30d22631a6
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user