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

Commit8fbef3b

Browse files
committed
Reduce need for palloc/pfree overhead in varstr_cmp() by using fixed-size
buffers on stack for short strings.
1 parent35223af commit8fbef3b

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

‎src/backend/utils/adt/varlena.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.92 2002/09/04 20:31:29 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.93 2002/11/17 23:01:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -736,36 +736,47 @@ int
736736
varstr_cmp(char*arg1,intlen1,char*arg2,intlen2)
737737
{
738738
intresult;
739-
char*a1p,
740-
*a2p;
741739

742740
/*
743741
* Unfortunately, there is no strncoll(), so in the non-C locale case
744742
* we have to do some memory copying. This turns out to be
745743
* significantly slower, so we optimize the case where LC_COLLATE is
746-
* C.
744+
* C. We also try to optimize relatively-short strings by avoiding
745+
* palloc/pfree overhead.
747746
*/
747+
#defineSTACKBUFLEN1024
748+
748749
if (!lc_collate_is_c())
749750
{
750-
a1p= (char*)palloc(len1+1);
751-
a2p= (char*)palloc(len2+1);
751+
chara1buf[STACKBUFLEN];
752+
chara2buf[STACKBUFLEN];
753+
char*a1p,
754+
*a2p;
755+
756+
if (len1 >=STACKBUFLEN)
757+
a1p= (char*)palloc(len1+1);
758+
else
759+
a1p=a1buf;
760+
if (len2 >=STACKBUFLEN)
761+
a2p= (char*)palloc(len2+1);
762+
else
763+
a2p=a2buf;
752764

753765
memcpy(a1p,arg1,len1);
754-
*(a1p+len1)='\0';
766+
a1p[len1]='\0';
755767
memcpy(a2p,arg2,len2);
756-
*(a2p+len2)='\0';
768+
a2p[len2]='\0';
757769

758770
result=strcoll(a1p,a2p);
759771

760-
pfree(a1p);
761-
pfree(a2p);
772+
if (len1 >=STACKBUFLEN)
773+
pfree(a1p);
774+
if (len2 >=STACKBUFLEN)
775+
pfree(a2p);
762776
}
763777
else
764778
{
765-
a1p=arg1;
766-
a2p=arg2;
767-
768-
result=strncmp(a1p,a2p,Min(len1,len2));
779+
result=strncmp(arg1,arg2,Min(len1,len2));
769780
if ((result==0)&& (len1!=len2))
770781
result= (len1<len2) ?-1 :1;
771782
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp