aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/like.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2005-05-25 22:59:33 +0000
committerBruce Momjian <bruce@momjian.us>2005-05-25 22:59:33 +0000
commit8c792fe9cbe1dcfdafcdc70b961be714631324ec (patch)
treed9a4e8a4c5848634e4e5fe86db831f2a0d44af45 /src/backend/utils/adt/like.c
parentbbb586ff211c2d304db4a64e8c3ea715a4ecebb5 (diff)
downloadpostgresql-8c792fe9cbe1dcfdafcdc70b961be714631324ec.tar.gz
postgresql-8c792fe9cbe1dcfdafcdc70b961be714631324ec.zip
At the head of wchareq, length of (multibyte) character is compared by
using pg_mblen. Therefore, pg_mblen is executed many times, and it becomes a bottleneck. This patch makes a short cut, and reduces execution frequency of pg_mblen by comparing the first byte first. a_ogawa
Diffstat (limited to 'src/backend/utils/adt/like.c')
-rw-r--r--src/backend/utils/adt/like.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 541bd0e629f..9289416ca46 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.59 2004/12/31 22:01:22 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.60 2005/05/25 22:59:33 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -50,12 +50,18 @@ static text *MB_do_like_escape(text *, text *);
static int
wchareq(unsigned char *p1, unsigned char *p2)
{
- int l;
+ int p1_len;
- l = pg_mblen(p1);
- if (pg_mblen(p2) != l)
+ /* Optimization: quickly compare the first byte. */
+ if(*p1 != *p2)
return (0);
- while (l--)
+
+ p1_len = pg_mblen(p1);
+ if (pg_mblen(p2) != p1_len)
+ return (0);
+
+ /* They are the same length */
+ while (p1_len--)
{
if (*p1++ != *p2++)
return (0);