From: Alan T. DeKok Date: Mon, 11 Apr 2022 13:16:25 +0000 (-0400) Subject: rearrange to hopefully help the compiler and clarify X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11c2bdc304078fef24119dcd2ec2d106f6f0a870;p=thirdparty%2Ffreeradius-server.git rearrange to hopefully help the compiler and clarify if it's inline, then separating the code paths for iter NULL (or not) should help. --- diff --git a/src/lib/util/dcursor.h b/src/lib/util/dcursor.h index a1e0bffdd18..cd0cc48a9a6 100644 --- a/src/lib/util/dcursor.h +++ b/src/lib/util/dcursor.h @@ -144,6 +144,17 @@ static inline void *dcursor_next(fr_dcursor_t *cursor, fr_dcursor_iter_t iter, v { void *next; + /* + * Fast path without custom iter + */ + if (!iter) { + if (likely(current != NULL)) return fr_dlist_next(cursor->dlist, current); + + if (cursor->at_end) return NULL; /* At tail of the list */ + + return fr_dlist_head(cursor->dlist); + } + /* * First time next has been called, or potentially * another call after we hit the end of the list. @@ -151,19 +162,14 @@ static inline void *dcursor_next(fr_dcursor_t *cursor, fr_dcursor_iter_t iter, v if (!current) { if (cursor->at_end) return NULL; /* At tail of the list */ - if (!iter) return (fr_dlist_head(cursor->dlist)); /* Fast path without custom iter */ - - current = fr_dlist_head(cursor->dlist); - next = iter(cursor->dlist, current, cursor->iter_uctx); + next = iter(cursor->dlist, fr_dlist_head(cursor->dlist), cursor->iter_uctx); VALIDATE(next); return next; } VALIDATE(current); - if (!iter) return fr_dlist_next(cursor->dlist, current); /* Fast path without custom iter */ - /* - * Pre-advance current + * Get the next entry, and pass it to the iterator. */ next = fr_dlist_next(cursor->dlist, current); if (!next) return NULL;