From efd0c16becbf45e3b0215e124fde75fee8fcbce4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 17 Aug 2022 11:12:35 -0400 Subject: 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 --- src/backend/commands/functioncmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/backend/commands/functioncmds.c') diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 59e3af626fa..e7e37146f69 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -419,7 +419,7 @@ interpret_function_parameter_list(ParseState *pstate, * Make sure no variables are referred to (this is probably dead * code now that add_missing_from is history). */ - if (list_length(pstate->p_rtable) != 0 || + if (pstate->p_rtable != NIL || contain_var_clause(def)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), @@ -1209,7 +1209,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt) returnsSet = false; } - if (list_length(trftypes_list) > 0) + if (trftypes_list != NIL) { ListCell *lc; Datum *arr; -- cgit v1.2.3