You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
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 thefirst cell of a List. Prior to v13 this was typically written asfor_each_cell(lc, lnext(list_head(list)))Commit1cff1b9 changed these tofor_each_cell(lc, list, list_second_cell(list))This patch introduces a new macro for_each_from() which expressesthe start point as a list index, allowing these to be written asfor_each_from(lc, list, 1)This is marginally more efficient, since ForEachState.i can beinitialized directly instead of backing into it from a ListCelladdress. It also seems clearer and less typo-prone.Some of the remaining uses of for_each_cell() look like they couldprofitably be changed to for_each_from(), but here I confined myselfto changing uses of list_second_cell().Also, fix for_each_cell_setup() and for_both_cell_setup() toconst-ify their arguments; that's a simple oversight in1cff1b9.Back-patch into v13, on the grounds that (1) the const-ificationis a minor bug fix, and (2) it's better for back-patching purposesif 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 in1cff1b9, and are unused as ofcc99baa. It seems unlikely that any third-party code wouldhave started to use them already; anyone who has can be directedto list_nth_cell instead.Discussion:https://postgr.es/m/CAApHDvpo1zj9KhEpU2cCRZfSM3Q6XGdhzuAS2v79PH7WJBkYVA@mail.gmail.com