Commit 226211f0 authored by Tatsuo Ishii's avatar Tatsuo Ishii

Optimization for bpcharlen, textlen, varcharlen in case of single byte

encodings.
parent e2548526
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.86 2001/11/08 04:05:13 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.87 2001/11/18 12:07:07 ishii Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -598,6 +598,10 @@ bpcharlen(PG_FUNCTION_ARGS) ...@@ -598,6 +598,10 @@ bpcharlen(PG_FUNCTION_ARGS)
BpChar *arg = PG_GETARG_BPCHAR_P(0); BpChar *arg = PG_GETARG_BPCHAR_P(0);
#ifdef MULTIBYTE #ifdef MULTIBYTE
/* optimization for single byte encoding */
if (pg_database_encoding_max_length() <= 1)
PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
PG_RETURN_INT32( PG_RETURN_INT32(
pg_mbstrlen_with_len(VARDATA(arg), VARSIZE(arg) - VARHDRSZ) pg_mbstrlen_with_len(VARDATA(arg), VARSIZE(arg) - VARHDRSZ)
); );
...@@ -806,6 +810,10 @@ varcharlen(PG_FUNCTION_ARGS) ...@@ -806,6 +810,10 @@ varcharlen(PG_FUNCTION_ARGS)
VarChar *arg = PG_GETARG_VARCHAR_P(0); VarChar *arg = PG_GETARG_VARCHAR_P(0);
#ifdef MULTIBYTE #ifdef MULTIBYTE
/* optimization for single byte encoding */
if (pg_database_encoding_max_length() <= 1)
PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
PG_RETURN_INT32( PG_RETURN_INT32(
pg_mbstrlen_with_len(VARDATA(arg), VARSIZE(arg) - VARHDRSZ) pg_mbstrlen_with_len(VARDATA(arg), VARSIZE(arg) - VARHDRSZ)
); );
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.74 2001/10/25 05:49:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.75 2001/11/18 12:07:07 ishii Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -240,22 +240,13 @@ textlen(PG_FUNCTION_ARGS) ...@@ -240,22 +240,13 @@ textlen(PG_FUNCTION_ARGS)
text *t = PG_GETARG_TEXT_P(0); text *t = PG_GETARG_TEXT_P(0);
#ifdef MULTIBYTE #ifdef MULTIBYTE
unsigned char *s; /* optimization for single byte encoding */
int len, if (pg_database_encoding_max_length() <= 1)
l, PG_RETURN_INT32(VARSIZE(t) - VARHDRSZ);
wl;
PG_RETURN_INT32(
len = 0; pg_mbstrlen_with_len(VARDATA(t), VARSIZE(t) - VARHDRSZ)
s = VARDATA(t); );
l = VARSIZE(t) - VARHDRSZ;
while (l > 0)
{
wl = pg_mblen(s);
l -= wl;
s += wl;
len++;
}
PG_RETURN_INT32(len);
#else #else
PG_RETURN_INT32(VARSIZE(t) - VARHDRSZ); PG_RETURN_INT32(VARSIZE(t) - VARHDRSZ);
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment