git.postgresql.org Git - postgresql.git/commit

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: 4a319fc) | patch
Avoid using list_length() to test for empty list.
2022年8月17日 15:12:35 +0000 (11:12 -0400)
2022年8月17日 15:12:35 +0000 (11:12 -0400)
commit efd0c16becbf45e3b0215e124fde75fee8fcbce4
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
28 files changed:
src/backend/catalog/objectaddress.c diff | blob | blame | history
src/backend/catalog/pg_depend.c diff | blob | blame | history
src/backend/commands/event_trigger.c diff | blob | blame | history
src/backend/commands/functioncmds.c diff | blob | blame | history
src/backend/commands/publicationcmds.c diff | blob | blame | history
src/backend/commands/statscmds.c diff | blob | blame | history
src/backend/commands/subscriptioncmds.c diff | blob | blame | history
src/backend/commands/tablecmds.c diff | blob | blame | history
src/backend/commands/typecmds.c diff | blob | blame | history
src/backend/executor/execPartition.c diff | blob | blame | history
src/backend/libpq/auth.c diff | blob | blame | history
src/backend/libpq/hba.c diff | blob | blame | history
src/backend/optimizer/path/costsize.c diff | blob | blame | history
src/backend/optimizer/plan/createplan.c diff | blob | blame | history
src/backend/optimizer/plan/planner.c diff | blob | blame | history
src/backend/partitioning/partprune.c diff | blob | blame | history
src/backend/replication/logical/tablesync.c diff | blob | blame | history
src/backend/replication/pgoutput/pgoutput.c diff | blob | blame | history
src/backend/rewrite/rewriteDefine.c diff | blob | blame | history
src/backend/statistics/mcv.c diff | blob | blame | history
src/backend/storage/lmgr/lmgr.c diff | blob | blame | history
src/backend/utils/adt/jsonb_gin.c diff | blob | blame | history
src/backend/utils/adt/jsonpath_exec.c diff | blob | blame | history
src/backend/utils/adt/jsonpath_gram.y diff | blob | blame | history
src/backend/utils/adt/ruleutils.c diff | blob | blame | history
src/backend/utils/adt/selfuncs.c diff | blob | blame | history
src/backend/utils/adt/tsquery.c diff | blob | blame | history
src/test/modules/test_ddl_deparse/test_ddl_deparse.c diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /