From c352c484d456eae57573e3a359fe8911efa74c26 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 | 44 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/backend/utils/Gen_fmgrtab.sh.in b/src/backend/utils/Gen_fmgrtab.sh.in index 62cc9a4219..00e6d89c24 100644 --- a/src/backend/utils/Gen_fmgrtab.sh.in +++ b/src/backend/utils/Gen_fmgrtab.sh.in @@ -250,36 +250,38 @@ cat >> $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