Re: Propose a new function - list_is_empty
Peter Smith <smithpb2250@gmail.com>
From: Peter Smith <smithpb2250@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-08-16T05:29:29Z
Lists: pgsql-hackers
Attachments
- v2-0001-use-NIL-test-for-empty-List-checks.patch (application/octet-stream) patch v2-0001
On Tue, Aug 16, 2022 at 11:27 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > > Peter Smith <smithpb2250@gmail.com> writes: > > During a recent code review I was going to suggest that some new code > > would be more readable if the following: > > if (list_length(alist) == 0) ... > > > was replaced with: > > if (list_is_empty(alist)) ... > > > but then I found that actually no such function exists. > > That's because the *correct* way to write it is either "alist == NIL" > or just "!alist". I don't think we need yet another way to spell > that, and I'm entirely not on board with replacing either of those > idioms. But if you want to get rid of overcomplicated uses of > list_length() in favor of one of those spellings, have at it. Done, and tested OK with make check-world. PSA. ------ Kind Regards, Peter Smith. Fujitsu Australia.
Commits
-
Avoid using list_length() to test for empty list.
- efd0c16becbf 16.0 landed