The more I think about it and look at the code, the more I like the usage of the loop style proposed in the previous 0003 patch (which automatically declares a loop variable for the scope of the loop using a second for loop).
I did some testing on godbolt.org and both versions of the macros result in the same assembly when compiling with -O2 (and even -O1) when compiling with ancient versions of gcc (5.1) and clang (3.0): https://godbolt.org/z/WqfTbhe4e So attached is now an updated patchset that only includes these even easier to use foreach macros. I also updated some of the comments and moved modifying foreach_delete_current and foreach_current_index to their own commit. On Thu, 14 Dec 2023 at 16:54, Jelte Fennema-Nio <postg...@jeltef.nl> wrote: > > On Fri, 1 Dec 2023 at 05:20, Nathan Bossart <nathandboss...@gmail.com> wrote: > > Could we simplify it with something like the following? > > Great suggestion! Updated the patchset accordingly. > > This made it also easy to change the final patch to include the > automatic scoped declaration logic for all of the new macros. I quite > like how the calling code changes to not have to declare the variable. > But it's definitely a larger divergence from the status quo than > without patch 0003. So I'm not sure if it's desired. > > Finally, I also renamed the functions to use foreach instead of > for_each, since based on this thread that seems to be the generally > preferred naming.
v7-0001-Add-macros-for-looping-through-a-list-without-nee.patch
Description: Binary data
v7-0003-Use-new-foreach_xyz-macros-in-a-few-places.patch
Description: Binary data
v7-0002-Make-some-macros-that-used-cell-work-with-new-for.patch
Description: Binary data