|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -736,36 +736,47 @@ int
|
736 | 736 | varstr_cmp(char*arg1,intlen1,char*arg2,intlen2)
|
737 | 737 | {
|
738 | 738 | intresult;
|
739 |
| -char*a1p, |
740 |
| -*a2p; |
741 | 739 |
|
742 | 740 | /*
|
743 | 741 | * Unfortunately, there is no strncoll(), so in the non-C locale case
|
744 | 742 | * we have to do some memory copying. This turns out to be
|
745 | 743 | * 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. |
747 | 746 | */
|
| 747 | +#defineSTACKBUFLEN1024 |
| 748 | + |
748 | 749 | if (!lc_collate_is_c())
|
749 | 750 | {
|
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; |
752 | 764 |
|
753 | 765 | memcpy(a1p,arg1,len1);
|
754 |
| -*(a1p+len1)='\0'; |
| 766 | +a1p[len1]='\0'; |
755 | 767 | memcpy(a2p,arg2,len2);
|
756 |
| -*(a2p+len2)='\0'; |
| 768 | +a2p[len2]='\0'; |
757 | 769 |
|
758 | 770 | result=strcoll(a1p,a2p);
|
759 | 771 |
|
760 |
| -pfree(a1p); |
761 |
| -pfree(a2p); |
| 772 | +if (len1 >=STACKBUFLEN) |
| 773 | +pfree(a1p); |
| 774 | +if (len2 >=STACKBUFLEN) |
| 775 | +pfree(a2p); |
762 | 776 | }
|
763 | 777 | else
|
764 | 778 | {
|
765 |
| -a1p=arg1; |
766 |
| -a2p=arg2; |
767 |
| - |
768 |
| -result=strncmp(a1p,a2p,Min(len1,len2)); |
| 779 | +result=strncmp(arg1,arg2,Min(len1,len2)); |
769 | 780 | if ((result==0)&& (len1!=len2))
|
770 | 781 | result= (len1<len2) ?-1 :1;
|
771 | 782 | }
|
|