Re: Small improvements to pg_list.h's linitial(), lsecond(), lthird() etc macros

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <dgrowleyml@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2020-09-27T23:58:55Z
Lists: pgsql-hackers
David Rowley <dgrowleyml@gmail.com> writes:
> I'm a bit unsure about llast()'s new double evaluation of the list.
> Perhaps I can add a new inline function named list_last_cell() to get
> around that... Or maybe it doesn't matter. I'm not quite sure what's
> best there.

Double evaluation bad, especially in a macro that has not had such a
hazard for the last twenty-plus years.

It might not be worth mucking with llast, as it's not used very heavily
I believe.  But if it is, then let's add another inline function.

			regards, tom lane



Commits

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

  2. Minor mop-up for List improvements.

  3. Improve pg_list.h's linitial(), lsecond() and co macros