Re: Add new for_each macros for iterating over a List that do not require ListCell pointer

From: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add new for_each macros for iterating over a List that do not require ListCell pointer
Date: 2023-12-18 13:30:12
Message-ID: CAGECzQQW7coOKjFXZq2A6mEjrvUB-GGmhiEpqsUCehZzY8frXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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 <postgres(at)jeltef(dot)nl> wrote:
>
> On Fri, 1 Dec 2023 at 05:20, Nathan Bossart <nathandbossart(at)gmail(dot)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.

Attachment Content-Type Size
v7-0001-Add-macros-for-looping-through-a-list-without-nee.patch application/octet-stream 3.9 KB
v7-0003-Use-new-foreach_xyz-macros-in-a-few-places.patch application/octet-stream 7.2 KB
v7-0002-Make-some-macros-that-used-cell-work-with-new-for.patch application/octet-stream 2.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2023-12-18 13:52:41 Re: Remove MSVC scripts from the tree
Previous Message Alexander Korotkov 2023-12-18 13:29:35 Re: Postgres picks suboptimal index after building of an extended statistics