From: | Peter Smith <smithpb2250(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Propose a new function - list_is_empty |
Date: | 2022-08-16 01:19:47 |
Message-ID: | CAHut+PtQYe+ENX5KrONMfugf0q6NHg4hR5dAhqEXEc2eefFeig@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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.
~~~
Searching the PG source found many cases using all kinds of
inconsistent ways to test for empty Lists:
e.g.1 if (list_length(alist) > 0)
e.g.2 if (list_length(alist) == 0)
e.g.3 if (list_length(alist) != 0)
e.g.4 if (list_length(alist) >= 1)
e.g.5 if (list_length(alist) < 1)
Of course, all of them work OK as-is, but by using list_is_empty all
those can be made consistent and often also more readable as to the
code intent.
Patch 0001 adds a new function 'list_is_empty'.
Patch 0002 makes use of it.
Thoughts?
------
Kind Regards,
Peter Smith.
Fujitsu Australia
Attachment | Content-Type | Size |
---|---|---|
v1-0002-list_is_empty-use-the-new-function.patch | application/octet-stream | 18.5 KB |
v1-0001-list_is_empty-new-function.patch | application/octet-stream | 714 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2022-08-16 01:27:56 | Re: Propose a new function - list_is_empty |
Previous Message | Andres Freund | 2022-08-16 01:16:14 | Re: Cleaning up historical portability baggage |