summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-03-23 14:26:43 +0400
committerAlexander Barkov <bar@mariadb.org>2016-03-23 14:26:43 +0400
commit0a83caf4a90cc98281571404dfc9ee3a718120d8 (patch)
treef92abd9a7cc951227ba820c4b51198d18d4b29ca /strings
parent0d42d4e9e02074416e0149ada0edd584cbb233a6 (diff)
downloadmariadb-git-0a83caf4a90cc98281571404dfc9ee3a718120d8.tar.gz
Removing duplicate code: sharing implementation of "strnxfrm"
between gbk_chinese_ci and big5_chinese_ci.
Diffstat (limited to 'strings')
-rw-r--r--strings/ctype-big5.c38
-rw-r--r--strings/ctype-gbk.c35
-rw-r--r--strings/strcoll.ic41
3 files changed, 46 insertions, 68 deletions
diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c
index d549bbcc7a4..962931913a2 100644
--- a/strings/ctype-big5.c
+++ b/strings/ctype-big5.c
@@ -45,8 +45,6 @@
#define isbig5code(c,d) (isbig5head(c) && isbig5tail(d))
#define big5code(c,d) (((uchar)(c) <<8) | (uchar)(d))
-#define big5head(e) ((uchar)(e>>8))
-#define big5tail(e) ((uchar)(e&0xff))
#define MY_FUNCTION_NAME(x) my_ ## x ## _big5
#define IS_MB1_CHAR(x) ((uchar) (x) < 0x80)
@@ -850,38 +848,6 @@ static uint16 big5strokexfrm(uint16 i)
}
-static size_t
-my_strnxfrm_big5(CHARSET_INFO *cs,
- uchar *dst, size_t dstlen, uint nweights,
- const uchar *src, size_t srclen, uint flags)
-{
- uchar *d0= dst;
- uchar *de= dst + dstlen;
- const uchar *se= src + srclen;
- const uchar *sort_order= cs->sort_order;
-
- for (; dst < de && src < se && nweights; nweights--)
- {
- if (my_charlen(cs, (const char *) src, (const char *) se) > 1)
- {
- /*
- Note, it is safe not to check (src < se)
- in the code below, because my_charlen() would
- not return 2 if src was too short
- */
- uint16 e= big5strokexfrm((uint16) big5code(*src, *(src + 1)));
- *dst++= big5head(e);
- if (dst < de)
- *dst++= big5tail(e);
- src+= 2;
- }
- else
- *dst++= sort_order ? sort_order[*src++] : *src++;
- }
- return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
-}
-
-
static uint mbcharlen_big5(CHARSET_INFO *cs __attribute__((unused)), uint c)
{
return (isbig5head(c)? 2 : 1);
@@ -6719,6 +6685,8 @@ my_mb_wc_big5(CHARSET_INFO *cs __attribute__((unused)),
#define MY_FUNCTION_NAME(x) my_ ## x ## _big5_chinese_ci
#define WEIGHT_MB1(x) (sort_order_big5[(uchar) (x)])
#define WEIGHT_MB2(x,y) (big5code(x, y))
+#define WEIGHT_MB2_FRM(x,y) (big5strokexfrm((uint16) WEIGHT_MB2(x, y)))
+#define DEFINE_STRNXFRM
#include "strcoll.ic"
@@ -6733,7 +6701,7 @@ static MY_COLLATION_HANDLER my_collation_handler_big5_chinese_ci=
NULL, /* init */
my_strnncoll_big5_chinese_ci,
my_strnncollsp_big5_chinese_ci,
- my_strnxfrm_big5,
+ my_strnxfrm_big5_chinese_ci,
my_strnxfrmlen_simple,
my_like_range_mb,
my_wildcmp_mb,
diff --git a/strings/ctype-gbk.c b/strings/ctype-gbk.c
index 88c09763513..e4e015a59d2 100644
--- a/strings/ctype-gbk.c
+++ b/strings/ctype-gbk.c
@@ -3451,38 +3451,6 @@ static uint16 gbksortorder(uint16 i)
}
-static size_t
-my_strnxfrm_gbk(CHARSET_INFO *cs,
- uchar *dst, size_t dstlen, uint nweights,
- const uchar *src, size_t srclen, uint flags)
-{
- uchar *d0= dst;
- uchar *de= dst + dstlen;
- const uchar *se= src + srclen;
- const uchar *sort_order= cs->sort_order;
-
- for (; dst < de && src < se && nweights; nweights--)
- {
- if (my_charlen(cs, (const char *) src, (const char *) se) > 1)
- {
- /*
- Note, it is safe not to check (src < se)
- in the code below, because my_charlen() would
- not return 2 if src was too short
- */
- uint16 e= gbksortorder((uint16) gbkcode(*src, *(src + 1)));
- *dst++= gbkhead(e);
- if (dst < de)
- *dst++= gbktail(e);
- src+= 2;
- }
- else
- *dst++= sort_order ? sort_order[*src++] : *src++;
- }
- return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
-}
-
-
static uint mbcharlen_gbk(CHARSET_INFO *cs __attribute__((unused)),uint c)
{
return (isgbkhead(c)? 2 : 1);
@@ -10652,6 +10620,7 @@ my_mb_wc_gbk(CHARSET_INFO *cs __attribute__((unused)),
#define MY_FUNCTION_NAME(x) my_ ## x ## _gbk_chinese_ci
#define WEIGHT_MB1(x) (sort_order_gbk[(uchar) (x)])
#define WEIGHT_MB2(x,y) (gbksortorder(gbkcode(x,y)))
+#define DEFINE_STRNXFRM
#include "strcoll.ic"
@@ -10666,7 +10635,7 @@ static MY_COLLATION_HANDLER my_collation_handler_gbk_chinese_ci=
NULL, /* init */
my_strnncoll_gbk_chinese_ci,
my_strnncollsp_gbk_chinese_ci,
- my_strnxfrm_gbk,
+ my_strnxfrm_gbk_chinese_ci,
my_strnxfrmlen_simple,
my_like_range_mb,
my_wildcmp_mb,
diff --git a/strings/strcoll.ic b/strings/strcoll.ic
index 4bced593a23..4ce362c1675 100644
--- a/strings/strcoll.ic
+++ b/strings/strcoll.ic
@@ -262,6 +262,45 @@ MY_FUNCTION_NAME(strnncollsp)(CHARSET_INFO *cs __attribute__((unused)),
return 0;
}
+
+#ifdef DEFINE_STRNXFRM
+#ifndef WEIGHT_MB2_FRM
+#define WEIGHT_MB2_FRM(x,y) WEIGHT_MB2(x,y)
+#endif
+
+static size_t
+MY_FUNCTION_NAME(strnxfrm)(CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
+{
+ uchar *d0= dst;
+ uchar *de= dst + dstlen;
+ const uchar *se= src + srclen;
+ const uchar *sort_order= cs->sort_order;
+
+ for (; dst < de && src < se && nweights; nweights--)
+ {
+ if (my_charlen(cs, (const char *) src, (const char *) se) > 1)
+ {
+ /*
+ Note, it is safe not to check (src < se)
+ in the code below, because my_charlen() would
+ not return 2 if src was too short
+ */
+ uint16 e= WEIGHT_MB2_FRM(src[0], src[1]);
+ *dst++= (uchar) (e >> 8);
+ if (dst < de)
+ *dst++= (uchar) (e & 0xFF);
+ src+= 2;
+ }
+ else
+ *dst++= sort_order ? sort_order[*src++] : *src++;
+ }
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
+}
+#endif /* DEFINE_STRNXFRM */
+
+
/*
We usually include this file at least two times from the same source file,
for the _ci and the _bin collations. Prepare for the second inclusion.
@@ -273,3 +312,5 @@ MY_FUNCTION_NAME(strnncollsp)(CHARSET_INFO *cs __attribute__((unused)),
#undef WEIGHT_MB3
#undef WEIGHT_MB4
#undef WEIGHT_PAD_SPACE
+#undef WEIGHT_MB2_FRM
+#undef DEFINE_STRNXFRM