pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add for_each_from, to simplify loops starting from non-first lis
Date: Tue, 29 Sep 2020 00:33:40 +0000
Message-ID: <E1kN3aO-00077d-3E@gemulon.postgresql.org> (raw)

Add for_each_from, to simplify loops starting from non-first list cells.

We have a dozen or so places that need to iterate over all but the
first cell of a List.  Prior to v13 this was typically written as
        for_each_cell(lc, lnext(list_head(list)))
Commit 1cff1b95a changed these to
        for_each_cell(lc, list, list_second_cell(list))
This patch introduces a new macro for_each_from() which expresses
the start point as a list index, allowing these to be written as
        for_each_from(lc, list, 1)
This is marginally more efficient, since ForEachState.i can be
initialized directly instead of backing into it from a ListCell
address.  It also seems clearer and less typo-prone.

Some of the remaining uses of for_each_cell() look like they could
profitably be changed to for_each_from(), but here I confined myself
to changing uses of list_second_cell().

Also, fix for_each_cell_setup() and for_both_cell_setup() to
const-ify their arguments; that's a simple oversight in 1cff1b95a.

Back-patch into v13, on the grounds that (1) the const-ification
is a minor bug fix, and (2) it's better for back-patching purposes
if we only have two ways to write these loops rather than three.

In HEAD, also remove list_third_cell() and list_fourth_cell(),
which were also introduced in 1cff1b95a, and are unused as of
cc99baa43.  It seems unlikely that any third-party code would
have started to use them already; anyone who has can be directed
to list_nth_cell instead.

Discussion: https://postgr.es/m/CAApHDvpo1zj9KhEpU2cCRZfSM3Q6XGdhzuAS2v79PH7WJBkYVA@mail.gmail.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/67b2ceea01576933a1dc881ef6a65403e03483ee

Modified Files
--------------
src/backend/commands/tablecmds.c        |  2 +-
src/backend/nodes/nodeFuncs.c           |  4 ++--
src/backend/optimizer/plan/createplan.c |  2 +-
src/backend/optimizer/plan/planner.c    |  4 ++--
src/backend/parser/parse_agg.c          |  4 ++--
src/backend/utils/adt/jsonpath_gram.y   |  2 +-
src/backend/utils/adt/ruleutils.c       |  8 +++-----
src/backend/utils/adt/selfuncs.c        |  2 +-
src/include/nodes/pg_list.h             | 32 +++++++++++++++++++++++++++++---
9 files changed, 42 insertions(+), 18 deletions(-)



view thread (2+ messages)

Message-ID: <E1kN3aO-00077d-3E@gemulon.postgresql.org>
Permalink:  ../E1kN3aO-00077d-3E@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kN3aO-00077d-3E@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Add for_each_from, to simplify loops starting from non-first lis
  In-Reply-To: <E1kN3aO-00077d-3E@gemulon.postgresql.org>
  References: <E1kN3aO-00077d-3E@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox