From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | Jelte Fennema <postgres(at)jeltef(dot)nl> |
Cc: | 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-10-25 08:51:55 |
Message-ID: | 202310250851.3wmj444nmqf6@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2023-Oct-24, Jelte Fennema wrote:
> Many usages of the foreach macro in the Postgres codebase only use the
> ListCell variable to then get its value. This adds macros that
> simplify iteration code for that very common use case. Instead of
> passing a ListCell you can pass a variable of the type of its
> contents. This IMHO improves readability of the code by reducing the
> total amount of code while also essentially forcing the use of useful
> variable names.
+1 for getting rid of useless "lc" variables.
Looking at for_each_ptr() I think it may be cleaner to follow
palloc_object()'s precedent and make it foreach_object() instead (I have
no love for the extra underscore, but I won't object to it either). And
like foreach_node, have it receive a type name to add a cast to.
I'd imagine something like
SubscriptionRelState *rstate;
foreach_object(SubscriptionRelState *, rstate, table_states_not_ready)
{
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2023-10-25 09:17:03 | Re: walwriter interacts quite badly with synchronous_commit=off |
Previous Message | Bharath Rupireddy | 2023-10-25 08:48:06 | Re: [PoC] pg_upgrade: allow to upgrade publisher node |