Tighten coding of fmgr_isbuiltin() ... managed to speed it up
authorTom Lane
Mon, 25 Jan 1999 00:44:53 +0000 (00:44 +0000)
committerTom Lane
Mon, 25 Jan 1999 00:44:53 +0000 (00:44 +0000)
by about 10% which seems to be good for half a percent or so of a SELECT.

src/backend/utils/Gen_fmgrtab.sh.in

index c31decfc532384c3532e132a322090e604c32c4f..40f1dccb5dcda1fd8ad6f297e1594ffc2fe15949 100644 (file)
@@ -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 <
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: Gen_fmgrtab.sh.in,v 1.12 1998/10/28 19:38:47 tgl Exp $
+ * $Id: Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
  *
  * NOTES
  * ******************************
@@ -197,7 +197,7 @@ cat > $TABCFILE <
  *
  *
  * 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
  *
@@ -250,36 +250,38 @@ cat >> $TABCFILE <
 #endif /* WIN32 */
 };
 
-static int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1;
+/* Note FMGR_NBUILTINS excludes the guardian entry, which is probably
+ * not really needed at all ...
+ */
+#define FMGR_NBUILTINS  ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1)
 
 FmgrCall *fmgr_isbuiltin(Oid id)
 {
-    register int i = 0;
     int    low = 0;
-    int    high = fmgr_nbuiltins;
-
-    low = 0;
-    high = fmgr_nbuiltins;
-    while (low <= high) {
-   i = low + (high - low) / 2;
-   if (id == fmgr_builtins[i].proid)
-       break;
-   else if (id > 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;ii++) {
-   if (strcmp(name,fmgr_builtins[i].funcName) == 0)
-       return(fmgr_builtins[i].func);
+    for (i=0; ii++) {
+       if (strcmp(name,fmgr_builtins[i].funcName) == 0)
+           return(fmgr_builtins[i].func);
     }
     return((func_ptr) NULL);
 }