|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.132 2005/08/24 17:50:00 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.133 2005/08/26 17:40:36 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -840,40 +840,22 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2)
|
840 | 840 | * C. We also try to optimize relatively-short strings by avoiding
|
841 | 841 | * palloc/pfree overhead.
|
842 | 842 | */
|
| 843 | +if (lc_collate_is_c()) |
| 844 | +{ |
| 845 | +result=strncmp(arg1,arg2,Min(len1,len2)); |
| 846 | +if ((result==0)&& (len1!=len2)) |
| 847 | +result= (len1<len2) ?-1 :1; |
| 848 | +} |
| 849 | +else |
| 850 | +{ |
843 | 851 | #defineSTACKBUFLEN1024
|
844 | 852 |
|
845 |
| -if (!lc_collate_is_c()) |
846 |
| -{ |
847 | 853 | chara1buf[STACKBUFLEN];
|
848 | 854 | chara2buf[STACKBUFLEN];
|
849 | 855 | char*a1p,
|
850 | 856 | *a2p;
|
851 | 857 |
|
852 |
| -#ifndefWIN32 |
853 |
| - |
854 |
| -if (len1 >=STACKBUFLEN) |
855 |
| -a1p= (char*)palloc(len1+1); |
856 |
| -else |
857 |
| -a1p=a1buf; |
858 |
| -if (len2 >=STACKBUFLEN) |
859 |
| -a2p= (char*)palloc(len2+1); |
860 |
| -else |
861 |
| -a2p=a2buf; |
862 |
| - |
863 |
| -memcpy(a1p,arg1,len1); |
864 |
| -a1p[len1]='\0'; |
865 |
| -memcpy(a2p,arg2,len2); |
866 |
| -a2p[len2]='\0'; |
867 |
| - |
868 |
| -result=strcoll(a1p,a2p); |
869 |
| - |
870 |
| -if (a1p!=a1buf) |
871 |
| -pfree(a1p); |
872 |
| -if (a2p!=a2buf) |
873 |
| -pfree(a2p); |
874 |
| - |
875 |
| -#else/* WIN32 */ |
876 |
| - |
| 858 | +#ifdefWIN32 |
877 | 859 | /* Win32 does not have UTF-8, so we need to map to UTF-16 */
|
878 | 860 | if (GetDatabaseEncoding()==PG_UTF8)
|
879 | 861 | {
|
@@ -943,17 +925,28 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2)
|
943 | 925 |
|
944 | 926 | returnresult;
|
945 | 927 | }
|
| 928 | +#endif/* WIN32 */ |
946 | 929 |
|
947 |
| -/* Win32 has strncoll(), so use it to avoid copying */ |
948 |
| -return_strncoll(arg1,arg2,Min(len1,len2)); |
| 930 | +if (len1 >=STACKBUFLEN) |
| 931 | +a1p= (char*)palloc(len1+1); |
| 932 | +else |
| 933 | +a1p=a1buf; |
| 934 | +if (len2 >=STACKBUFLEN) |
| 935 | +a2p= (char*)palloc(len2+1); |
| 936 | +else |
| 937 | +a2p=a2buf; |
949 | 938 |
|
950 |
| -#endif/* WIN32 */ |
951 |
| -} |
952 |
| -else |
953 |
| -{ |
954 |
| -result=strncmp(arg1,arg2,Min(len1,len2)); |
955 |
| -if ((result==0)&& (len1!=len2)) |
956 |
| -result= (len1<len2) ?-1 :1; |
| 939 | +memcpy(a1p,arg1,len1); |
| 940 | +a1p[len1]='\0'; |
| 941 | +memcpy(a2p,arg2,len2); |
| 942 | +a2p[len2]='\0'; |
| 943 | + |
| 944 | +result=strcoll(a1p,a2p); |
| 945 | + |
| 946 | +if (a1p!=a1buf) |
| 947 | +pfree(a1p); |
| 948 | +if (a2p!=a2buf) |
| 949 | +pfree(a2p); |
957 | 950 | }
|
958 | 951 |
|
959 | 952 | returnresult;
|
|