Propose a new function - list_is_empty - Mailing list pgsql-hackers

From Peter Smith
Subject Propose a new function - list_is_empty
Date
Msg-id CAHut+PtQYe+ENX5KrONMfugf0q6NHg4hR5dAhqEXEc2eefFeig@mail.gmail.com
Whole thread Raw
Responses Re: Propose a new function - list_is_empty
List 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

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Cleaning up historical portability baggage
Next
From: Tom Lane
Date:
Subject: Re: Propose a new function - list_is_empty