From 443e24beb71fe83ed6f4f16743618020f35aad1a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 25 Jan 1999 00:44:53 +0000 Subject: [PATCH] Tighten coding of fmgr_isbuiltin() ... managed to speed it up by about 10% which seems to be good for half a percent or so of a SELECT. --- src/backend/utils/Gen_fmgrtab.sh.in | 50 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/backend/utils/Gen_fmgrtab.sh.in b/src/backend/utils/Gen_fmgrtab.sh.in index c31decfc53..40f1dccb5d 100644 --- a/src/backend/utils/Gen_fmgrtab.sh.in +++ b/src/backend/utils/Gen_fmgrtab.sh.in @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.12 1998/10/28 19:38:47 tgl Exp $ +# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $ # # NOTES # Passes any -D options on to cpp prior to generating the list @@ -83,7 +83,7 @@ cat > $HFILE < $TABCFILE <> $TABCFILE < fmgr_builtins[i].proid) - low = i + 1; - else - high = i - 1; - } - if (id == fmgr_builtins[i].proid) - return(&fmgr_builtins[i]); - return((FmgrCall *) NULL); + int high = FMGR_NBUILTINS - 1; + + /* Loop invariant: low is the first index that could contain target + * entry, and high is the last index that could contain it. + */ + while (low <= high) { + int i = (high + low) / 2; + FmgrCall * ptr = &fmgr_builtins[i]; + if (id == ptr->proid) + return ptr; + else if (id > ptr->proid) + low = i + 1; + else + high = i - 1; + } + return (FmgrCall *) NULL; } func_ptr fmgr_lookupByName(char *name) { int i; - for (i=0;i