Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit443e24b

Browse files
committed
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.
1 parent49b6be2 commit443e24b

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

‎src/backend/utils/Gen_fmgrtab.sh.in

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.12 1998/10/28 19:38:47 tgl Exp $
11+
# $Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
1212
#
1313
# NOTES
1414
# Passes any -D options on to cpp prior to generating the list
@@ -83,7 +83,7 @@ cat > $HFILE <<FuNkYfMgRsTuFf
8383
*
8484
* Copyright (c) 1994, Regents of the University of California
8585
*
86-
*$Id: Gen_fmgrtab.sh.in,v 1.12 1998/10/28 19:38:47 tgl Exp $
86+
*$Id: Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
8787
*
8888
* NOTES
8989
*******************************
@@ -197,7 +197,7 @@ cat > $TABCFILE <<FuNkYfMgRtAbStUfF
197197
*
198198
*
199199
* IDENTIFICATION
200-
*$Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.12 1998/10/28 19:38:47 tgl Exp $
200+
*$Header: /cvsroot/pgsql/src/backend/utils/Attic/Gen_fmgrtab.sh.in,v 1.13 1999/01/25 00:44:53 tgl Exp $
201201
*
202202
* NOTES
203203
*
@@ -250,36 +250,38 @@ cat >> $TABCFILE <<FuNkYfMgRtAbStUfF
250250
#endif /* WIN32 */
251251
};
252252
253-
static int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1;
253+
/* Note FMGR_NBUILTINS excludes the guardian entry, which is probably
254+
* not really needed at all ...
255+
*/
256+
#define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1)
254257
255258
FmgrCall *fmgr_isbuiltin(Oid id)
256259
{
257-
register int i = 0;
258260
intlow = 0;
259-
inthigh =fmgr_nbuiltins;
260-
261-
low= 0;
262-
high= fmgr_nbuiltins;
263-
while (low <= high) {
264-
i =low+ (high - low) / 2;
265-
if (id == fmgr_builtins[i].proid)
266-
break;
267-
elseif (id> fmgr_builtins[i].proid)
268-
low = i + 1;
269-
else
270-
high= i- 1;
271-
}
272-
if (id == fmgr_builtins[i].proid)
273-
return(&fmgr_builtins[i]);
274-
return((FmgrCall *) NULL);
261+
inthigh =FMGR_NBUILTINS - 1;
262+
263+
/* Loop invariant:lowis the first index that could contain target
264+
* entry, andhighis the last index that could contain it.
265+
*/
266+
while (low<=high) {
267+
int i = (high + low) / 2;
268+
FmgrCall * ptr = &fmgr_builtins[i];
269+
if (id== ptr->proid)
270+
return ptr;
271+
else if (id > ptr->proid)
272+
low= i+ 1;
273+
else
274+
high = i - 1;
275+
}
276+
return (FmgrCall *) NULL;
275277
}
276278
277279
func_ptr fmgr_lookupByName(char *name)
278280
{
279281
int i;
280-
for (i=0;i<fmgr_nbuiltins;i++) {
281-
if (strcmp(name,fmgr_builtins[i].funcName) == 0)
282-
return(fmgr_builtins[i].func);
282+
for (i=0; i<FMGR_NBUILTINS;i++) {
283+
if (strcmp(name,fmgr_builtins[i].funcName) == 0)
284+
return(fmgr_builtins[i].func);
283285
}
284286
return((func_ptr) NULL);
285287
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp