Re: Propose a new function - list_is_empty

From: Peter Smith <smithpb2250(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Propose a new function - list_is_empty
Date: 2022-08-16 05:29:29
Message-ID: CAHut+PsQC3-Y=mdo4A-ja9zjzeN0VhS2Vpfoei9JtySGOBkQ9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Aug 16, 2022 at 11:27 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Peter Smith <smithpb2250(at)gmail(dot)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.

Attachment Content-Type Size
v2-0001-use-NIL-test-for-empty-List-checks.patch application/octet-stream 18.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2022-08-16 05:31:15 Re: Logical WAL sender unresponsive during decoding commit
Previous Message Shinoda, Noriyoshi (PN Japan FSIP) 2022-08-16 05:27:36 [PG15 Doc] remove "tty" connect string from manual