postgresql/src/include/nodes
Tom Lane 56fe008996 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
2020-09-28 20:33:13 -04:00
..
bitmapset.h Move bitmap_hash and bitmap_match to bitmapset.c. 2020-02-24 17:17:43 +05:30
execnodes.h Move resolution of AlternativeSubPlan choices to the planner. 2020-09-27 12:51:28 -04:00
extensible.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
lockoptions.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
makefuncs.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
memnodes.h Revert "Specialize MemoryContextMemAllocated()." 2020-03-19 12:21:50 -07:00
nodeFuncs.h Suppress unnecessary RelabelType nodes in yet more cases. 2020-08-19 14:07:49 -04:00
nodes.h Move resolution of AlternativeSubPlan choices to the planner. 2020-09-27 12:51:28 -04:00
params.h Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
parsenodes.h Allow CURRENT_ROLE where CURRENT_USER is accepted 2020-09-17 11:40:08 +02:00
pathnodes.h Move resolution of AlternativeSubPlan choices to the planner. 2020-09-27 12:51:28 -04:00
pg_list.h Add for_each_from, to simplify loops starting from non-first list cells. 2020-09-28 20:33:13 -04:00
plannodes.h Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
primnodes.h Move resolution of AlternativeSubPlan choices to the planner. 2020-09-27 12:51:28 -04:00
print.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
readfuncs.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
replnodes.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
supportnodes.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tidbitmap.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
value.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00