Re: Converting tab-complete.c's else-if chain to a switch
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Cc: Andres Freund <andres@anarazel.de>
Date: 2024-07-13T17:16:14Z
Lists: pgsql-hackers
Attachments
- v1-0001-Invent-MatchAnyN-option-for-tab-complete.c-s-Matc.patch (text/x-diff) patch v1-0001
- v1-0002-Split-out-most-of-psql_completion-into-a-separate.patch (text/x-diff) patch v1-0002
- v1-0003-Install-preprocessor-infrastructure-for-tab-compl.patch (text/x-diff) patch v1-0003
- v1-0004-Convert-tab-complete-s-long-else-if-chain-to-a-sw.patch (text/x-diff) patch v1-0004
- v1-0005-Run-pgindent-on-tab-complete.in.c.patch (text/x-diff) patch v1-0005
- convert_tabcomplete.pl (text/plain)
- pre-convert.diff.txt (text/x-diff) patch
- post-convert.diff.txt (text/x-diff) patch
I wrote:
> Per discussion elsewhere [1], I've been looking at $SUBJECT.
Here's a finished patchset to perform this change. I don't
believe it has any material effect on runtime behavior or
performance, but it does achieve what Andres anticipated
would happen: the compile time for tab-complete.c drops
considerably. With gcc 8.5.0 I see the time drop from
about 3 seconds to about 0.7. The win is less noticeable
with clang version 15.0 on a Mac M1: from about 0.7s to 0.45s.
Of course the main point is the hope that it will work at all
with MSVC, but I'm not in a position to test that.
The most painful part of this is all the changes like
COMPLETE_WITH("ADD", "DROP", "OWNER TO", "RENAME", "SET",
"VALIDATE CONSTRAINT");
+ break;
/* ALTER DOMAIN <sth> DROP */
- else if (Matches("ALTER", "DOMAIN", MatchAny, "DROP"))
+ case Matches("ALTER", "DOMAIN", MatchAny, "DROP"):
COMPLETE_WITH("CONSTRAINT", "DEFAULT", "NOT NULL");
+ break;
/* ALTER DOMAIN <sth> DROP|RENAME|VALIDATE CONSTRAINT */
I despaired of doing that accurately by hand, so I wrote
a Perl script to do it. The script can cope with all but
about three of the existing tests; those have to be manually
modified before running the script, and then the actual
"switch()" has to be inserted afterwards. There won't be
any need to commit the script, since it's a one-time tool,
but I've included it for documentation's sake, along with
the "pre-convert.diff" and "post-convert.diff" manual patch
steps that are required to construct the complete 0004 patch.
I'm going to add this to the September CF, but I'd really
rather get it reviewed and committed pretty quickly.
Even with the helper script, I'm not eager to have to
rebase this a bunch of times.
regards, tom lane
Commits
-
Don't hard-code the input file name in gen_tabcomplete.pl's output.
- c75c6f8d280a 18.0 landed
-
Avoid possible segfault in psql's tab completion.
- 95eb4cd4ff06 18.0 landed
-
Convert tab-complete's long else-if chain to a switch statement.
- f391d9dc93a2 18.0 landed
-
Prepare tab-complete.c for preprocessing.
- bd1276a3c943 18.0 landed
-
Invent "MatchAnyN" option for tab-complete.c's Matches/MatchesCS.
- ef0938f7bdd0 18.0 landed