aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/oracle_compat.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-06-06 22:17:01 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-06-06 22:17:01 +0000
commit7845bfc095547a7ef16844236e76ffc5bec50c70 (patch)
tree81c298011f6689af2e1eed9a4032be359fed825b /src/backend/utils/adt/oracle_compat.c
parentb8312c5fe75245f24443286d00ed4b3d61ea6f83 (diff)
downloadpostgresql-7845bfc095547a7ef16844236e76ffc5bec50c70.tar.gz
postgresql-7845bfc095547a7ef16844236e76ffc5bec50c70.zip
Dept of second thoughts: don't use the new wide-character upper/lower
code if we are running in a single-byte encoding. No point in the extra overhead in that case.
Diffstat (limited to 'src/backend/utils/adt/oracle_compat.c')
-rw-r--r--src/backend/utils/adt/oracle_compat.c192
1 files changed, 99 insertions, 93 deletions
diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c
index ddbe890dd54..18a0e9e8042 100644
--- a/src/backend/utils/adt/oracle_compat.c
+++ b/src/backend/utils/adt/oracle_compat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.52 2004/05/26 16:16:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.53 2004/06/06 22:17:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -166,40 +166,44 @@ Datum
lower(PG_FUNCTION_ARGS)
{
#ifdef USE_WIDE_UPPER_LOWER
- text *string = PG_GETARG_TEXT_P(0);
- text *result;
- wchar_t *workspace;
- int i;
-
- workspace = texttowcs(string);
+ /* use wide char code only when max encoding length > one */
+ if (pg_database_encoding_max_length() > 1)
+ {
+ text *string = PG_GETARG_TEXT_P(0);
+ text *result;
+ wchar_t *workspace;
+ int i;
- for (i = 0; workspace[i] != 0; i++)
- workspace[i] = towlower(workspace[i]);
+ workspace = texttowcs(string);
- result = wcstotext(workspace, i);
+ for (i = 0; workspace[i] != 0; i++)
+ workspace[i] = towlower(workspace[i]);
- pfree(workspace);
+ result = wcstotext(workspace, i);
- PG_RETURN_TEXT_P(result);
+ pfree(workspace);
-#else /* !USE_WIDE_UPPER_LOWER */
+ PG_RETURN_TEXT_P(result);
+ }
+ else
+#endif /* USE_WIDE_UPPER_LOWER */
+ {
+ text *string = PG_GETARG_TEXT_P_COPY(0);
+ char *ptr;
+ int m;
- text *string = PG_GETARG_TEXT_P_COPY(0);
- char *ptr;
- int m;
+ /* Since we copied the string, we can scribble directly on the value */
+ ptr = VARDATA(string);
+ m = VARSIZE(string) - VARHDRSZ;
- /* Since we copied the string, we can scribble directly on the value */
- ptr = VARDATA(string);
- m = VARSIZE(string) - VARHDRSZ;
+ while (m-- > 0)
+ {
+ *ptr = tolower((unsigned char) *ptr);
+ ptr++;
+ }
- while (m-- > 0)
- {
- *ptr = tolower((unsigned char) *ptr);
- ptr++;
+ PG_RETURN_TEXT_P(string);
}
-
- PG_RETURN_TEXT_P(string);
-#endif /* USE_WIDE_UPPER_LOWER */
}
@@ -221,40 +225,44 @@ Datum
upper(PG_FUNCTION_ARGS)
{
#ifdef USE_WIDE_UPPER_LOWER
- text *string = PG_GETARG_TEXT_P(0);
- text *result;
- wchar_t *workspace;
- int i;
-
- workspace = texttowcs(string);
+ /* use wide char code only when max encoding length > one */
+ if (pg_database_encoding_max_length() > 1)
+ {
+ text *string = PG_GETARG_TEXT_P(0);
+ text *result;
+ wchar_t *workspace;
+ int i;
- for (i = 0; workspace[i] != 0; i++)
- workspace[i] = towupper(workspace[i]);
+ workspace = texttowcs(string);
- result = wcstotext(workspace, i);
+ for (i = 0; workspace[i] != 0; i++)
+ workspace[i] = towupper(workspace[i]);
- pfree(workspace);
+ result = wcstotext(workspace, i);
- PG_RETURN_TEXT_P(result);
+ pfree(workspace);
-#else /* !USE_WIDE_UPPER_LOWER */
+ PG_RETURN_TEXT_P(result);
+ }
+ else
+#endif /* USE_WIDE_UPPER_LOWER */
+ {
+ text *string = PG_GETARG_TEXT_P_COPY(0);
+ char *ptr;
+ int m;
- text *string = PG_GETARG_TEXT_P_COPY(0);
- char *ptr;
- int m;
+ /* Since we copied the string, we can scribble directly on the value */
+ ptr = VARDATA(string);
+ m = VARSIZE(string) - VARHDRSZ;
- /* Since we copied the string, we can scribble directly on the value */
- ptr = VARDATA(string);
- m = VARSIZE(string) - VARHDRSZ;
+ while (m-- > 0)
+ {
+ *ptr = toupper((unsigned char) *ptr);
+ ptr++;
+ }
- while (m-- > 0)
- {
- *ptr = toupper((unsigned char) *ptr);
- ptr++;
+ PG_RETURN_TEXT_P(string);
}
-
- PG_RETURN_TEXT_P(string);
-#endif /* USE_WIDE_UPPER_LOWER */
}
@@ -279,58 +287,56 @@ Datum
initcap(PG_FUNCTION_ARGS)
{
#ifdef USE_WIDE_UPPER_LOWER
- text *string = PG_GETARG_TEXT_P(0);
- text *result;
- wchar_t *workspace;
- int wasalnum = 0;
- int i;
-
- workspace = texttowcs(string);
-
- for (i = 0; workspace[i] != 0; i++)
+ /* use wide char code only when max encoding length > one */
+ if (pg_database_encoding_max_length() > 1)
{
- if (wasalnum)
- workspace[i] = towlower(workspace[i]);
- else
- workspace[i] = towupper(workspace[i]);
- wasalnum = iswalnum(workspace[i]);
- }
+ text *string = PG_GETARG_TEXT_P(0);
+ text *result;
+ wchar_t *workspace;
+ int wasalnum = 0;
+ int i;
- result = wcstotext(workspace, i);
+ workspace = texttowcs(string);
- pfree(workspace);
+ for (i = 0; workspace[i] != 0; i++)
+ {
+ if (wasalnum)
+ workspace[i] = towlower(workspace[i]);
+ else
+ workspace[i] = towupper(workspace[i]);
+ wasalnum = iswalnum(workspace[i]);
+ }
- PG_RETURN_TEXT_P(result);
+ result = wcstotext(workspace, i);
-#else /* !USE_WIDE_UPPER_LOWER */
+ pfree(workspace);
- text *string = PG_GETARG_TEXT_P_COPY(0);
- char *ptr;
- int m;
+ PG_RETURN_TEXT_P(result);
+ }
+ else
+#endif /* USE_WIDE_UPPER_LOWER */
+ {
+ text *string = PG_GETARG_TEXT_P_COPY(0);
+ int wasalnum = 0;
+ char *ptr;
+ int m;
- /* Since we copied the string, we can scribble directly on the value */
- ptr = VARDATA(string);
- m = VARSIZE(string) - VARHDRSZ;
+ /* Since we copied the string, we can scribble directly on the value */
+ ptr = VARDATA(string);
+ m = VARSIZE(string) - VARHDRSZ;
- if (m > 0)
- {
- *ptr = toupper((unsigned char) *ptr);
- ptr++;
- m--;
- }
+ while (m-- > 0)
+ {
+ if (wasalnum)
+ *ptr = tolower((unsigned char) *ptr);
+ else
+ *ptr = toupper((unsigned char) *ptr);
+ wasalnum = isalnum((unsigned char) *ptr);
+ ptr++;
+ }
- while (m-- > 0)
- {
- /* Oracle capitalizes after all non-alphanumeric */
- if (!isalnum((unsigned char) ptr[-1]))
- *ptr = toupper((unsigned char) *ptr);
- else
- *ptr = tolower((unsigned char) *ptr);
- ptr++;
+ PG_RETURN_TEXT_P(string);
}
-
- PG_RETURN_TEXT_P(string);
-#endif /* USE_WIDE_UPPER_LOWER */
}