From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Avoid using list_length() to test for empty list. |
Date: | 2022-08-17 15:12:43 |
Message-ID: | E1oOKin-001CGW-QC@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Avoid using list_length() to test for empty list.
The standard way to check for list emptiness is to compare the
List pointer to NIL; our list code goes out of its way to ensure
that that is the only representation of an empty list. (An
acceptable alternative is a plain boolean test for non-null
pointer, but explicit mention of NIL is usually preferable.)
Various places didn't get that memo and expressed the condition
with list_length(), which might not be so bad except that there
were such a variety of ways to check it exactly: equal to zero,
less than or equal to zero, less than one, yadda yadda. In the
name of code readability, let's standardize all those spellings
as "list == NIL" or "list != NIL". (There's probably some
microscopic efficiency gain too, though few of these look to be
at all performance-critical.)
A very small number of cases were left as-is because they seemed
more consistent with other adjacent list_length tests that way.
Peter Smith, with bikeshedding from a number of us
Discussion: https://postgr.es/m/CAHut+PtQYe+ENX5KrONMfugf0q6NHg4hR5dAhqEXEc2eefFeig@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/efd0c16becbf45e3b0215e124fde75fee8fcbce4
Modified Files
--------------
src/backend/catalog/objectaddress.c | 2 +-
src/backend/catalog/pg_depend.c | 2 +-
src/backend/commands/event_trigger.c | 8 ++++----
src/backend/commands/functioncmds.c | 4 ++--
src/backend/commands/publicationcmds.c | 6 +++---
src/backend/commands/statscmds.c | 4 ++--
src/backend/commands/subscriptioncmds.c | 2 +-
src/backend/commands/tablecmds.c | 8 ++++----
src/backend/commands/typecmds.c | 2 +-
src/backend/executor/execPartition.c | 2 +-
src/backend/libpq/auth.c | 4 ++--
src/backend/libpq/hba.c | 4 ++--
src/backend/optimizer/path/costsize.c | 2 +-
src/backend/optimizer/plan/createplan.c | 2 +-
src/backend/optimizer/plan/planner.c | 12 ++++++------
src/backend/partitioning/partprune.c | 2 +-
src/backend/replication/logical/tablesync.c | 8 ++++----
src/backend/replication/pgoutput/pgoutput.c | 2 +-
src/backend/rewrite/rewriteDefine.c | 2 +-
src/backend/statistics/mcv.c | 1 -
src/backend/storage/lmgr/lmgr.c | 2 +-
src/backend/utils/adt/jsonb_gin.c | 2 +-
src/backend/utils/adt/jsonpath_exec.c | 2 +-
src/backend/utils/adt/jsonpath_gram.y | 2 +-
src/backend/utils/adt/ruleutils.c | 2 +-
src/backend/utils/adt/selfuncs.c | 2 +-
src/backend/utils/adt/tsquery.c | 2 +-
src/test/modules/test_ddl_deparse/test_ddl_deparse.c | 2 +-
28 files changed, 47 insertions(+), 48 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2022-08-17 20:12:45 | pgsql: Make PlaceHolderInfo lookup O(1). |
Previous Message | Daniel Gustafsson | 2022-08-17 08:51:54 | pgsql: doc: Consistently spell case-insensitive |