From 36120d91e5f3ebad4f4df944bac98f33889cbcd3 Mon Sep 17 00:00:00 2001 From: Hartmut Brandt Date: Tue, 22 Feb 2005 07:58:53 +0000 Subject: [PATCH] Invent the LST_FOREACH macro for looping through a list. In contrast to the Lst_ForEach function this macro reduces the number of function calls per invocation by N + 1 (where N is the number of list elements) and increases code locality thereby increasing readability and (maybe) performance. --- usr.bin/make/lst.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usr.bin/make/lst.h b/usr.bin/make/lst.h index 3ec17f112e32..76535cc81f5a 100644 --- a/usr.bin/make/lst.h +++ b/usr.bin/make/lst.h @@ -162,6 +162,10 @@ LstNode *Lst_Member(Lst *, void *); void Lst_ForEach(Lst *, DoProc *, void *); #define Lst_ForEach(LST, FN, D) (Lst_ForEachFrom((LST), Lst_First(LST), \ (FN), (D))) + +#define LST_FOREACH(PTR, LST) \ + for ((PTR) = (LST)->firstPtr; (PTR) != NULL; (PTR) = (PTR)->nextPtr) + /* * Apply a function to all elements of a lst starting from a certain point. * If the list is circular, the application will wrap around to the