From 2bc8ca0ca2fefcfb63a37723d7a9bbb9ae76ceb1 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 5 Jun 2013 00:56:03 -0400 Subject: journal: loop less in MATCH_AND_TERM conditionals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AND term usually don't have many subterms (4 seems to be the maximum sensible number, e.g. _BOOT_ID && _SYSTEMD_UNIT && _PID && MESSAGE_ID). Nevertheless, the cost of checking each subterm can be relatively high, especially when the nested terms are compound, and it makes sense to minimize the number of checks. Instead of looping to the end and then again over the whole list once again after at least one term changed the offset, start the loop at the term which caused the change. This way ½ terms in the AND match are not checked unnecessarily again. --- src/shared/list.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/shared/list.h') diff --git a/src/shared/list.h b/src/shared/list.h index 47f275a019..96d6237974 100644 --- a/src/shared/list.h +++ b/src/shared/list.h @@ -123,3 +123,10 @@ #define LIST_FOREACH_AFTER(name,i,p) \ for ((i) = (p)->name##_next; (i); (i) = (i)->name##_next) + +/* Loop starting from p->next until p->prev. + p can be adjusted meanwhile. */ +#define LIST_LOOP_BUT_ONE(name,i,head,p) \ + for ((i) = (p)->name##_next ? (p)->name##_next : (head); \ + (i) != (p); \ + (i) = (i)->name##_next ? (i)->name##_next : (head)) -- cgit v1.2.3-54-g00ecf