Skip to content

Commit a9118fc

Browse files
committed
The idea of using _strncoll() on Windows doesn't work. Revert to same
code as we use on other platforms when encoding is not UTF8.
1 parent 396526d commit a9118fc

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

src/backend/utils/adt/varlena.c

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* 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 $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -840,40 +840,22 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2)
840840
* C. We also try to optimize relatively-short strings by avoiding
841841
* palloc/pfree overhead.
842842
*/
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+
{
843851
#define STACKBUFLEN 1024
844852

845-
if (!lc_collate_is_c())
846-
{
847853
char a1buf[STACKBUFLEN];
848854
char a2buf[STACKBUFLEN];
849855
char *a1p,
850856
*a2p;
851857

852-
#ifndef WIN32
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+
#ifdef WIN32
877859
/* Win32 does not have UTF-8, so we need to map to UTF-16 */
878860
if (GetDatabaseEncoding() == PG_UTF8)
879861
{
@@ -943,17 +925,28 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2)
943925

944926
return result;
945927
}
928+
#endif /* WIN32 */
946929

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;
949938

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);
957950
}
958951

959952
return result;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy