]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
rearrange to hopefully help the compiler and clarify
authorAlan T. DeKok <aland@freeradius.org>
Mon, 11 Apr 2022 13:16:25 +0000 (09:16 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 11 Apr 2022 18:31:26 +0000 (14:31 -0400)
if it's inline, then separating the code paths for iter NULL (or not)
should help.

src/lib/util/dcursor.h

index a1e0bffdd18ad60692eeb9cc8c01bc432f83159b..cd0cc48a9a6113f71935ddc1a23c5e05ee9cc203 100644 (file)
@@ -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;