| 1 | /* Copyright (c) 2014, 2026, Oracle and/or its affiliates. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License, version 2.0, |
| 5 | as published by the Free Software Foundation. |
| 6 | |
| 7 | This program is designed to work with certain software (including |
| 8 | but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | as designated in a particular file or component or in included license |
| 10 | documentation. The authors of MySQL hereby grant you an additional |
| 11 | permission to link the program and your derivative works with the |
| 12 | separately licensed software that they have either included with |
| 13 | the program or referenced in the documentation. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License, version 2.0, for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 | |
| 24 | /* |
| 25 | In order to do benchmarking, configure in optimized mode, and build the |
| 26 | target |
| 27 | strings_strnxfrm-t |
| 28 | it is defined, but not built by default. Then run with: |
| 29 | ./bin/strings_strnxfrm-t --gtest_filter='Microbenchmarks*' |
| 30 | */ |
| 31 | |
| 32 | #include <gtest/gtest.h> |
| 33 | #include <inttypes.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <algorithm> |
| 36 | #include <memory> |
| 37 | #include <string> |
| 38 | #include <unordered_map> |
| 39 | #include <utility> |
| 40 | #include <vector> |
| 41 | |
| 42 | #include "my_inttypes.h" |
| 43 | #include "my_sys.h" |
| 44 | #include "template_utils.h" |
| 45 | #include "unittest/gunit/benchmark.h" |
| 46 | #include "unittest/gunit/strnxfrm.h" |
| 47 | |
| 48 | using std::make_pair; |
| 49 | using std::max; |
| 50 | using std::pair; |
| 51 | using std::string; |
| 52 | using std::to_string; |
| 53 | using std::unordered_map; |
| 54 | |
| 55 | namespace strnxfrm_unittest { |
| 56 | |
| 57 | namespace { |
| 58 | |
| 59 | // Simply print out an array. |
| 60 | void print_array(const uchar *arr, size_t len) { |
| 61 | for (size_t i = 0; i < len; ++i) { |
| 62 | fprintf(stderr, " %02x", arr[i]); |
| 63 | if ((i % 8) == 7 || i == len - 1) fprintf(stderr, "\n"); |
| 64 | } |
| 65 | fprintf(stderr, "\n"); |
| 66 | } |
| 67 | |
| 68 | // A function to compare two arrays and print them out in its entirety |
| 69 | // (for easier context) if they are not equal. |
| 70 | void expect_arrays_equal(const uchar *expected, const uchar *got, size_t len) { |
| 71 | int num_err = 0; |
| 72 | for (size_t i = 0; i < len && num_err < 5; ++i) { |
| 73 | EXPECT_EQ(expected[i], got[i]); |
| 74 | if (expected[i] != got[i]) ++num_err; |
| 75 | } |
| 76 | if (num_err) { |
| 77 | fprintf(stderr, "Expected:\n"); |
| 78 | for (size_t i = 0; i < len; ++i) { |
| 79 | fprintf(stderr, " %c%02x", expected[i] != got[i] ? '*' : ' ', |
| 80 | expected[i]); |
| 81 | if ((i % 8) == 7 || i == len - 1) fprintf(stderr, "\n"); |
| 82 | } |
| 83 | fprintf(stderr, "\nGot:\n"); |
| 84 | for (size_t i = 0; i < len; ++i) { |
| 85 | fprintf(stderr, " %c%02x", expected[i] != got[i] ? '*' : ' ', got[i]); |
| 86 | if ((i % 8) == 7 || i == len - 1) fprintf(stderr, "\n"); |
| 87 | } |
| 88 | fprintf(stderr, "\n"); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | CHARSET_INFO *init_collation(const char *name) { |
| 93 | MY_CHARSET_LOADER loader; |
| 94 | return my_collation_get_by_name(&loader, name, MYF(0)); |
| 95 | } |
| 96 | |
| 97 | int compare_through_strxfrm(CHARSET_INFO *cs, const char *a, const char *b) { |
| 98 | uchar abuf[256], bbuf[256]; |
| 99 | int alen = my_strnxfrm(cs, abuf, sizeof(abuf), pointer_cast<const uchar *>(a), |
| 100 | strlen(a)); |
| 101 | int blen = my_strnxfrm(cs, bbuf, sizeof(bbuf), pointer_cast<const uchar *>(b), |
| 102 | strlen(b)); |
| 103 | |
| 104 | if (false) // Enable this for debugging. |
| 105 | { |
| 106 | fprintf(stderr, "\n\nstrxfrm for '%s':\n", a); |
| 107 | print_array(abuf, alen); |
| 108 | fprintf(stderr, "strxfrm for '%s':\n", b); |
| 109 | print_array(bbuf, blen); |
| 110 | } |
| 111 | |
| 112 | int cmp = memcmp(abuf, bbuf, std::min(alen, blen)); |
| 113 | if (cmp != 0) return cmp; |
| 114 | |
| 115 | if (alen == blen) { |
| 116 | return 0; |
| 117 | } else { |
| 118 | return (alen < blen) ? -1 : 1; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | } // namespace |
| 123 | |
| 124 | #if !defined(NDEBUG) |
| 125 | // There is no point in benchmarking anything in debug mode. |
| 126 | const size_t num_iterations = 1ULL; |
| 127 | #else |
| 128 | // Set this so that each test case takes a few seconds. |
| 129 | // And set it back to a small value before pushing!! |
| 130 | // const size_t num_iterations= 20000000ULL; |
| 131 | const size_t num_iterations = 2ULL; |
| 132 | #endif |
| 133 | |
| 134 | class StrnxfrmTest : public ::testing::TestWithParam<size_t> { |
| 135 | protected: |
| 136 | void SetUp() override { |
| 137 | m_length = GetParam(); |
| 138 | m_src.assign(m_length, 0x20); |
| 139 | m_dst.assign(m_length, 0x20); |
| 140 | } |
| 141 | std::vector<uchar> m_src; |
| 142 | std::vector<uchar> m_dst; |
| 143 | size_t m_length; |
| 144 | }; |
| 145 | |
| 146 | size_t test_values[] = {1, 10, 100, 1000}; |
| 147 | |
| 148 | INSTANTIATE_TEST_SUITE_P(Strnxfrm, StrnxfrmTest, |
| 149 | ::testing::ValuesIn(test_values)); |
| 150 | |
| 151 | TEST_P(StrnxfrmTest, OriginalSrcDst) { |
| 152 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 153 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 154 | strnxfrm_orig(cs, &m_dst[0], m_length, m_length, &m_src[0], m_length, 192); |
| 155 | } |
| 156 | |
| 157 | TEST_P(StrnxfrmTest, OriginalUnrolledSrcDst) { |
| 158 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 159 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 160 | strnxfrm_orig_unrolled(cs, &m_dst[0], m_length, m_length, &m_src[0], |
| 161 | m_length, 192); |
| 162 | } |
| 163 | |
| 164 | TEST_P(StrnxfrmTest, ModifiedSrcDst) { |
| 165 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 166 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 167 | strnxfrm_new(cs, &m_dst[0], m_length, m_length, &m_src[0], m_length, 192); |
| 168 | } |
| 169 | |
| 170 | TEST_P(StrnxfrmTest, ModifiedUnrolledSrcDst) { |
| 171 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 172 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 173 | strnxfrm_new_unrolled(cs, &m_dst[0], m_length, m_length, &m_src[0], |
| 174 | m_length, 192); |
| 175 | } |
| 176 | |
| 177 | TEST_P(StrnxfrmTest, OriginalSrcSrc) { |
| 178 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 179 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 180 | strnxfrm_orig(cs, &m_src[0], m_length, m_length, &m_src[0], m_length, 192); |
| 181 | } |
| 182 | |
| 183 | TEST_P(StrnxfrmTest, OriginalUnrolledSrcSrc) { |
| 184 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 185 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 186 | strnxfrm_orig_unrolled(cs, &m_src[0], m_length, m_length, &m_src[0], |
| 187 | m_length, 192); |
| 188 | } |
| 189 | |
| 190 | TEST_P(StrnxfrmTest, ModifiedSrcSrc) { |
| 191 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 192 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 193 | strnxfrm_new(cs, &m_src[0], m_length, m_length, &m_src[0], m_length, 192); |
| 194 | } |
| 195 | |
| 196 | TEST_P(StrnxfrmTest, ModifiedUnrolledSrcSrc) { |
| 197 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 198 | for (size_t ix = 0; ix < num_iterations; ++ix) |
| 199 | strnxfrm_new_unrolled(cs, &m_src[0], m_length, m_length, &m_src[0], |
| 200 | m_length, 192); |
| 201 | } |
| 202 | |
| 203 | TEST(StrXfrmTest, SimpleUTF8Correctness) { |
| 204 | CHARSET_INFO *cs = init_collation("utf8mb3_bin"); |
| 205 | |
| 206 | const char *src = "abc æøå 日本語"; |
| 207 | unsigned char buf[32]; |
| 208 | |
| 209 | static const unsigned char full_answer_with_pad[32] = { |
| 210 | 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, // abc |
| 211 | 0x00, 0x20, // space |
| 212 | 0x00, 0xe6, 0x00, 0xf8, 0x00, 0xe5, // æøå |
| 213 | 0x00, 0x20, // space |
| 214 | 0x65, 0xe5, 0x67, 0x2c, 0x8a, 0x9e, // 日本語 |
| 215 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 216 | 0x00, 0x20, 0x00, 0x20 // space for padding |
| 217 | }; |
| 218 | |
| 219 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 220 | memset(buf, 0xff, sizeof(buf)); |
| 221 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 222 | expect_arrays_equal(full_answer_with_pad, buf, maxlen); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | TEST(StrXfrmTest, SimpleUTF8MB4Correctness) { |
| 227 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 228 | |
| 229 | const char *src = "abc æøå 日本語"; |
| 230 | unsigned char buf[30]; |
| 231 | |
| 232 | static const unsigned char full_answer_with_pad[30] = { |
| 233 | 0x1c, 0x47, 0x1c, 0x60, 0x1c, 0x7a, // abc |
| 234 | 0x02, 0x09, // space |
| 235 | 0x1c, 0x47, 0x1c, 0xaa, 0x1d, 0xdd, 0x1c, 0x47, // æøå |
| 236 | 0x02, 0x09, // space |
| 237 | 0xfb, 0x40, 0xe5, 0xe5, 0xfb, 0x40, 0xe7, 0x2c, |
| 238 | 0xfb, 0x41, 0x8a, 0x9e, // 日本語 |
| 239 | }; |
| 240 | |
| 241 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 242 | memset(buf, 0xff, sizeof(buf)); |
| 243 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 244 | expect_arrays_equal(full_answer_with_pad, buf, maxlen); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | TEST(StrXfrmTest, UTF8MB4Correctness_as_ci) { |
| 249 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_as_ci"); |
| 250 | |
| 251 | const char *src = "abc æøå 日本語"; |
| 252 | unsigned char buf[62]; |
| 253 | |
| 254 | static const unsigned char full_answer_with_pad[62] = { |
| 255 | 0x1c, 0x47, 0x1c, 0x60, 0x1c, 0x7a, // abc |
| 256 | 0x02, 0x09, // space |
| 257 | 0x1c, 0x47, 0x1c, 0xaa, 0x1d, 0xdd, 0x1c, 0x47, // æøå |
| 258 | 0x02, 0x09, // space |
| 259 | 0xfb, 0x40, 0xe5, 0xe5, 0xfb, 0x40, 0xe7, 0x2c, // 日本語 |
| 260 | 0xfb, 0x41, 0x8a, 0x9e, 0x00, 0x00, // level separator |
| 261 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // abc |
| 262 | 0x00, 0x20, // space |
| 263 | 0x00, 0x20, 0x01, 0x10, 0x00, 0x20, 0x00, 0x20, // æøå |
| 264 | 0x00, 0x2F, 0x00, 0x20, 0x00, 0x29, 0x00, 0x20, // space |
| 265 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20 // 日本語 |
| 266 | }; |
| 267 | |
| 268 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 269 | memset(buf, 0xff, sizeof(buf)); |
| 270 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 271 | expect_arrays_equal(full_answer_with_pad, buf, maxlen); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | TEST(StrXfrmTest, UTF8MB4Correctness_as_ci_1) { |
| 276 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_as_ci"); |
| 277 | // case insensitive |
| 278 | EXPECT_EQ(compare_through_strxfrm(cs, "Abc", "aBC"), 0); |
| 279 | // accent sensitive |
| 280 | EXPECT_NE(compare_through_strxfrm(cs, "ǍḄÇ", "ÁḆĈ"), 0); |
| 281 | EXPECT_NE(compare_through_strxfrm(cs, u8"\uA73A", u8"\uA738"), 0); |
| 282 | // Hangul decomposition |
| 283 | EXPECT_EQ(compare_through_strxfrm(cs, u8"\uAC00", u8"\u326E"), 0); |
| 284 | } |
| 285 | |
| 286 | TEST(StrXfrmTest, JapaneseUTF8MB4) { |
| 287 | CHARSET_INFO *cs = init_collation("utf8mb4_ja_0900_as_cs"); |
| 288 | |
| 289 | const char *src = |
| 290 | "\x61\x41\xCA\xAC\xCA\xAD" // latin 'aAʬʭ' |
| 291 | // Hiragana and Katakana 'ぁンはばぱ' |
| 292 | "\xE3\x81\x81\xE3\x83\xB3\xE3\x81\xAF\xE3\x81\xB0\xE3\x81\xB1" |
| 293 | // Japanese Han '亜熙憐' |
| 294 | "\xE4\xBA\x9C\xE7\x86\x99\xE6\x86\x90" |
| 295 | // Other Han '﨎㐀' |
| 296 | "\xEF\xA8\x8E\xE3\x90\x80" |
| 297 | // Greek, Coptic etc. 'αⲁаⳤퟻ' |
| 298 | "\xCE\xB1\xE2\xB2\x81\xD0\xB0\xE2\xB3\xA4\xED\x9F\xBB"; |
| 299 | |
| 300 | static const unsigned char full_answer_with_pad[156] = { |
| 301 | // Level 1 |
| 302 | 0x1C, 0x47, 0x1C, 0x47, 0x1F, 0xB1, 0x1F, 0xB5, // latin |
| 303 | 0x1F, 0xB6, 0x1F, 0xE7, 0x1F, 0xD0, 0x1F, 0xD0, // Hiragana and Katakana |
| 304 | 0x1F, 0xD0, 0x54, 0xA4, 0x6D, 0x76, 0x60, 0x00, // Japanese Han |
| 305 | 0xFB, 0x41, 0xFA, 0x0E, 0xFB, 0x80, 0xB4, 0x00, // Other Han |
| 306 | 0xFB, 0x86, 0x1F, 0xB9, 0xFB, 0x86, 0x1F, 0xE6, // Greek, Coptic etc. |
| 307 | 0xFB, 0x86, 0x20, 0x22, 0xFB, 0x86, 0x1F, 0xF1, 0xFB, 0x86, 0x1F, 0xE6, |
| 308 | 0xFB, 0x86, 0x1F, 0xF0, 0xFB, 0x86, 0x3D, 0x59, 0x00, |
| 309 | 0x00, // Level separator |
| 310 | // Level 2 |
| 311 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // latin |
| 312 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // Hiragana and Katakana |
| 313 | 0x00, 0x37, 0x00, 0x20, 0x00, 0x38, 0x00, 0x20, 0x00, 0x20, 0x00, |
| 314 | 0x20, // Japanese Han |
| 315 | 0x00, 0x20, 0x00, 0x20, // Other Han |
| 316 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // Greek, Coptic etc. |
| 317 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, // Level separator |
| 318 | // Level 3 |
| 319 | 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, // latin |
| 320 | 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, // Hiragana and Katakana |
| 321 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, |
| 322 | 0x02, // Japanese Han |
| 323 | 0x00, 0x02, 0x00, 0x02, // Other Han |
| 324 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x04, // Greek, Coptic etc. |
| 325 | 0x00, 0x04, 0x00, 0x04, 0x00, 0x02}; |
| 326 | |
| 327 | unsigned char buf[sizeof(full_answer_with_pad)]; |
| 328 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 329 | memset(buf, 0xff, sizeof(buf)); |
| 330 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 331 | expect_arrays_equal(full_answer_with_pad, buf, maxlen); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | TEST(StrXfrmTest, Japanese_ks_UTF8MB4) { |
| 336 | CHARSET_INFO *cs = init_collation("utf8mb4_ja_0900_as_cs_ks"); |
| 337 | |
| 338 | /* |
| 339 | Weights of Japanese Han, Other Han, Greek, Coptic are not changed comparing |
| 340 | to the test result of collation utf8mb4_ja_0900_as_cs (in test |
| 341 | JapaneseUtf8mb4 above). But additional quaternary weight is added for |
| 342 | Hiragana and Katakana characters. |
| 343 | */ |
| 344 | const char *src = |
| 345 | "\x61\x41\xCA\xAC\xCA\xAD" // latin 'aAʬʭ' |
| 346 | // Hiragana and Katakana 'ぁンはばぱ' |
| 347 | "\xE3\x81\x81\xE3\x83\xB3\xE3\x81\xAF\xE3\x81\xB0\xE3\x81\xB1" |
| 348 | // Japanese Han '亜熙憐' |
| 349 | "\xE4\xBA\x9C\xE7\x86\x99\xE6\x86\x90" |
| 350 | // Other Han '﨎㐀' |
| 351 | "\xEF\xA8\x8E\xE3\x90\x80" |
| 352 | // Greek, Coptic etc. 'αⲁаⳤퟻ' |
| 353 | "\xCE\xB1\xE2\xB2\x81\xD0\xB0\xE2\xB3\xA4\xED\x9F\xBB" |
| 354 | // Prefix context 'さー' and 'サー' |
| 355 | "\xE3\x81\x95\xE3\x83\xBC\xE3\x82\xB5\xE3\x83\xBC"; |
| 356 | |
| 357 | static const unsigned char full_answer_with_pad[] = { |
| 358 | // Level 1 |
| 359 | 0x1C, 0x47, 0x1C, 0x47, 0x1F, 0xB1, 0x1F, 0xB5, // latin |
| 360 | 0x1F, 0xB6, 0x1F, 0xE7, 0x1F, 0xD0, 0x1F, 0xD0, // Hiragana and Katakana |
| 361 | 0x1F, 0xD0, 0x54, 0xA4, 0x6D, 0x76, 0x60, 0x00, // Japanese Han |
| 362 | 0xFB, 0x41, 0xFA, 0x0E, 0xFB, 0x80, 0xB4, 0x00, // Other Han |
| 363 | 0xFB, 0x86, 0x1F, 0xB9, 0xFB, 0x86, 0x1F, 0xE6, // Greek, Coptic etc. |
| 364 | 0xFB, 0x86, 0x20, 0x22, 0xFB, 0x86, 0x1F, 0xF1, 0xFB, 0x86, 0x1F, 0xE6, |
| 365 | 0xFB, 0x86, 0x1F, 0xF0, 0xFB, 0x86, 0x3D, 0x59, 0x1F, 0xC1, 0x1F, 0xB6, |
| 366 | 0x1F, 0xC1, 0x1F, 0xB6, // Prefix context |
| 367 | 0x00, 0x00, // Level separator |
| 368 | // Level 2 |
| 369 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // latin |
| 370 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // Hiragana and Katakana |
| 371 | 0x00, 0x37, 0x00, 0x20, 0x00, 0x38, 0x00, 0x20, 0x00, 0x20, 0x00, |
| 372 | 0x20, // Japanese Han |
| 373 | 0x00, 0x20, 0x00, 0x20, // Other Han |
| 374 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // Greek, Coptic etc. |
| 375 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 376 | 0x00, 0x20, // Prefix context |
| 377 | 0x00, 0x00, // Level separator |
| 378 | // Level 3 |
| 379 | 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, // latin |
| 380 | 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, // Hiragana and Katakana |
| 381 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, |
| 382 | 0x02, // Japanese Han |
| 383 | 0x00, 0x02, 0x00, 0x02, // Other Han |
| 384 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x04, // Greek, Coptic etc. |
| 385 | 0x00, 0x04, 0x00, 0x04, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, |
| 386 | 0x00, 0x0E, // Prefix context |
| 387 | 0x00, 0x0C, 0x00, 0x21, 0x00, 0x00, // Level separator |
| 388 | // Level 4 |
| 389 | 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, // Hiragana and Katakana |
| 390 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, 0x00, |
| 391 | 0x08 // Prefix context |
| 392 | }; |
| 393 | |
| 394 | unsigned char buf[sizeof(full_answer_with_pad)]; |
| 395 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 396 | memset(buf, 0xff, sizeof(buf)); |
| 397 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 398 | expect_arrays_equal(full_answer_with_pad, buf, maxlen); |
| 399 | } |
| 400 | |
| 401 | CHARSET_INFO *as_cs = init_collation("utf8mb4_ja_0900_as_cs"); |
| 402 | CHARSET_INFO *as_cs_ks = init_collation("utf8mb4_ja_0900_as_cs_ks"); |
| 403 | // utf8 "にほんご" |
| 404 | const char *str1 = "\xE3\x81\xAB\xE3\x81\xBB\xE3\x82\x93\xE3\x81\x94"; |
| 405 | // utf8 "ニホンゴ" |
| 406 | const char *str2 = "\xE3\x83\x8B\xE3\x83\x9B\xE3\x83\xB3\xE3\x82\xB4"; |
| 407 | EXPECT_EQ(compare_through_strxfrm(as_cs, str1, str2), 0); |
| 408 | EXPECT_LT(compare_through_strxfrm(as_cs_ks, str1, str2), 0); |
| 409 | |
| 410 | str1 = "\xE3\x81\xAF\xE3\x81\xAF"; // utf8 "はは" |
| 411 | str2 = "\xE3\x81\xAF\xE3\x83\x8F"; // utf8 "はハ" |
| 412 | const char *str3 = "\xE3\x83\x8F\xE3\x81\xAF"; // utf8 "ハは" |
| 413 | const char *str4 = "\xE3\x83\x8F\xE3\x83\x8F"; // utf8 "ハハ" |
| 414 | EXPECT_EQ(compare_through_strxfrm(as_cs, str1, str2), 0); |
| 415 | EXPECT_EQ(compare_through_strxfrm(as_cs, str2, str3), 0); |
| 416 | EXPECT_EQ(compare_through_strxfrm(as_cs, str3, str4), 0); |
| 417 | EXPECT_LT(compare_through_strxfrm(as_cs_ks, str1, str2), 0); |
| 418 | EXPECT_LT(compare_through_strxfrm(as_cs_ks, str2, str3), 0); |
| 419 | EXPECT_LT(compare_through_strxfrm(as_cs_ks, str3, str4), 0); |
| 420 | } |
| 421 | |
| 422 | TEST(StrXfrmTest, JapaneseUTF8MB4_1) { |
| 423 | CHARSET_INFO *cs = init_collation("utf8mb4_ja_0900_as_cs"); |
| 424 | // Japanese HE followed with Handakuten mark |
| 425 | const char *src1 = "\xE3\x81\xB8\xE3\x82\x99"; |
| 426 | // Japanese HE followed with voiced length mark |
| 427 | const char *src2 = "\xE3\x81\xB8\xE3\x82\x9E"; |
| 428 | |
| 429 | /* |
| 430 | When the voiced length mark is after 'HE', it should sort before |
| 431 | 'HE followed with Handakuten mark'on tertiary level. |
| 432 | */ |
| 433 | static const unsigned char answer1[] = {0x1F, 0xD3, 0x00, 0x00, 0x00, |
| 434 | 0x20, 0x00, 0x37, 0x00, 0x00, |
| 435 | 0x00, 0x0E, 0x00, 0x02}; |
| 436 | static const unsigned char answer2[] = { |
| 437 | 0x1F, 0xD3, 0x1F, 0xD3, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, |
| 438 | 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x01, 0x00, 0x21}; |
| 439 | |
| 440 | unsigned char buf[32]; |
| 441 | |
| 442 | size_t buf_len = sizeof(answer1); |
| 443 | memset(buf, 0xff, sizeof(buf)); |
| 444 | my_strnxfrm(cs, buf, buf_len, pointer_cast<const uchar *>(src1), |
| 445 | strlen(src1)); |
| 446 | expect_arrays_equal(answer1, buf, buf_len); |
| 447 | |
| 448 | buf_len = sizeof(answer2); |
| 449 | memset(buf, 0xff, sizeof(buf)); |
| 450 | my_strnxfrm(cs, buf, buf_len, pointer_cast<const uchar *>(src2), |
| 451 | strlen(src2)); |
| 452 | expect_arrays_equal(answer2, buf, buf_len); |
| 453 | } |
| 454 | |
| 455 | TEST(StrXfrmTest, UTF8MB4PadCorrectness) { |
| 456 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_as_cs"); |
| 457 | |
| 458 | const char *src = "abc "; |
| 459 | unsigned char buf[46]; |
| 460 | |
| 461 | static const unsigned char full_answer[52] = { |
| 462 | 0x1c, 0x47, 0x1c, 0x60, 0x1c, 0x7a, // abc |
| 463 | 0x02, 0x09, 0x02, 0x09, 0x02, 0x09, |
| 464 | 0x02, 0x09, // Four spaces. |
| 465 | 0x00, 0x00, // Level separator. |
| 466 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, // Accents for abc. |
| 467 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 468 | 0x00, 0x20, // Accents for four spaces. |
| 469 | 0x00, 0x00, // Level separator. |
| 470 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, // Case for abc. |
| 471 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 472 | 0x00, 0x02, // Case for four spaces. |
| 473 | }; |
| 474 | |
| 475 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 476 | SCOPED_TRACE("maxlen=" + to_string(maxlen) + "/" + to_string(sizeof(buf))); |
| 477 | memset(buf, 0xff, sizeof(buf)); |
| 478 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 479 | expect_arrays_equal(full_answer, buf, maxlen); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | TEST(StrXfrmTest, NullPointer) { |
| 484 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 485 | unsigned char buf[256]; |
| 486 | |
| 487 | memset(buf, 0x33, sizeof(buf)); |
| 488 | cs->coll->strnxfrm(cs, buf, sizeof(buf), sizeof(buf), nullptr, 0, |
| 489 | MY_STRXFRM_PAD_TO_MAXLEN); |
| 490 | |
| 491 | for (size_t i = 0; i < sizeof(buf); ++i) { |
| 492 | EXPECT_EQ(0, buf[i]); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Benchmark based on reduced test case in Bug #83247 / #24788778. |
| 497 | // |
| 498 | // Note: This benchmark does not exercise any real multibyte characters; |
| 499 | // it is mostly exercising padding. If we change the test string to contain |
| 500 | // e.g. Japanese characters, performance goes down by ~20%. |
| 501 | static void BM_SimpleUTF8(size_t num_iterations) { |
| 502 | StopBenchmarkTiming(); |
| 503 | |
| 504 | CHARSET_INFO *cs = init_collation("utf8mb3_bin"); |
| 505 | |
| 506 | static constexpr int key_cols = 12; |
| 507 | static constexpr int set_key_cols = 6; // Only the first half is set. |
| 508 | static constexpr int key_col_chars = 80; |
| 509 | static constexpr int bytes_per_char = 3; |
| 510 | static constexpr int key_bytes = key_col_chars * bytes_per_char; |
| 511 | static constexpr int buffer_bytes = key_cols * key_bytes; |
| 512 | |
| 513 | unsigned char source[buffer_bytes]; |
| 514 | unsigned char dest[buffer_bytes]; |
| 515 | |
| 516 | const char *content = "PolyFilla27773"; |
| 517 | const int len = strlen(content); |
| 518 | memset(source, 0, sizeof(source)); |
| 519 | |
| 520 | for (int k = 0, offset = 0; k < set_key_cols; ++k, offset += key_bytes) { |
| 521 | memcpy(source + offset, content, len); |
| 522 | } |
| 523 | |
| 524 | StartBenchmarkTiming(); |
| 525 | for (size_t i = 0; i < num_iterations; ++i) { |
| 526 | for (int k = 0, offset = 0; k < key_cols; ++k, offset += key_bytes) { |
| 527 | if (k < set_key_cols) { |
| 528 | my_strnxfrm(cs, dest + offset, key_bytes, source + offset, len); |
| 529 | } else { |
| 530 | my_strnxfrm(cs, dest + offset, key_bytes, source + offset, 0); |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | StopBenchmarkTiming(); |
| 535 | } |
| 536 | BENCHMARK(BM_SimpleUTF8) |
| 537 | |
| 538 | // Verifies using my_charpos to find the length of a string. |
| 539 | // hp_hash.c does this extensively. Not really a strnxfrm benchmark, |
| 540 | // but belongs to the same optimization effort. |
| 541 | static void BM_UTF8MB4StringLength(size_t num_iterations) { |
| 542 | StopBenchmarkTiming(); |
| 543 | |
| 544 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 545 | |
| 546 | // Some English text, then some Norwegian text, then some Japanese, |
| 547 | // and then a few emoji (the last with skin tone modifiers). |
| 548 | const char *content = |
| 549 | "Premature optimization is the root of all evil. " |
| 550 | "Våre norske tegn bør æres. 日本語が少しわかります。 " |
| 551 | "✌️🐶👩🏽"; |
| 552 | const int len = strlen(content); |
| 553 | int tot_len = 0; |
| 554 | |
| 555 | StartBenchmarkTiming(); |
| 556 | for (size_t i = 0; i < num_iterations; ++i) { |
| 557 | tot_len += my_charpos(cs, content, content + len, len / cs->mbmaxlen); |
| 558 | } |
| 559 | StopBenchmarkTiming(); |
| 560 | |
| 561 | EXPECT_NE(0, tot_len); |
| 562 | SetBytesProcessed(num_iterations * strlen(content)); |
| 563 | } |
| 564 | BENCHMARK(BM_UTF8MB4StringLength) |
| 565 | |
| 566 | // Benchmark testing the default recommended collation for 8.0, without |
| 567 | // stressing padding as much, but still testing only Latin letters. |
| 568 | static void BM_SimpleUTF8MB4(size_t num_iterations) { |
| 569 | StopBenchmarkTiming(); |
| 570 | |
| 571 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 572 | |
| 573 | const char *content = |
| 574 | "This is a rather long string that contains only " |
| 575 | "simple letters that are available in ASCII. This is a common special " |
| 576 | "case that warrants a benchmark on its own, even if the character set " |
| 577 | "and collation supports much more complicated scenarios."; |
| 578 | const int len = strlen(content); |
| 579 | |
| 580 | // Just recorded from a trial run on the string above. |
| 581 | static constexpr uchar expected[] = { |
| 582 | 0x1e, 0x95, 0x1d, 0x18, 0x1d, 0x32, 0x1e, 0x71, 0x02, 0x09, 0x1d, 0x32, |
| 583 | 0x1e, 0x71, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x09, 0x1e, 0x33, 0x1c, 0x47, |
| 584 | 0x1e, 0x95, 0x1d, 0x18, 0x1c, 0xaa, 0x1e, 0x33, 0x02, 0x09, 0x1d, 0x77, |
| 585 | 0x1d, 0xdd, 0x1d, 0xb9, 0x1c, 0xf4, 0x02, 0x09, 0x1e, 0x71, 0x1e, 0x95, |
| 586 | 0x1e, 0x33, 0x1d, 0x32, 0x1d, 0xb9, 0x1c, 0xf4, 0x02, 0x09, 0x1e, 0x95, |
| 587 | 0x1d, 0x18, 0x1c, 0x47, 0x1e, 0x95, 0x02, 0x09, 0x1c, 0x7a, 0x1d, 0xdd, |
| 588 | 0x1d, 0xb9, 0x1e, 0x95, 0x1c, 0x47, 0x1d, 0x32, 0x1d, 0xb9, 0x1e, 0x71, |
| 589 | 0x02, 0x09, 0x1d, 0xdd, 0x1d, 0xb9, 0x1d, 0x77, 0x1f, 0x0b, 0x02, 0x09, |
| 590 | 0x1e, 0x71, 0x1d, 0x32, 0x1d, 0xaa, 0x1e, 0x0c, 0x1d, 0x77, 0x1c, 0xaa, |
| 591 | 0x02, 0x09, 0x1d, 0x77, 0x1c, 0xaa, 0x1e, 0x95, 0x1e, 0x95, 0x1c, 0xaa, |
| 592 | 0x1e, 0x33, 0x1e, 0x71, 0x02, 0x09, 0x1e, 0x95, 0x1d, 0x18, 0x1c, 0x47, |
| 593 | 0x1e, 0x95, 0x02, 0x09, 0x1c, 0x47, 0x1e, 0x33, 0x1c, 0xaa, 0x02, 0x09, |
| 594 | 0x1c, 0x47, 0x1e, 0xe3, 0x1c, 0x47, 0x1d, 0x32, 0x1d, 0x77, 0x1c, 0x47, |
| 595 | 0x1c, 0x60, 0x1d, 0x77, 0x1c, 0xaa, 0x02, 0x09, 0x1d, 0x32, 0x1d, 0xb9, |
| 596 | 0x02, 0x09, 0x1c, 0x47, 0x1e, 0x71, 0x1c, 0x7a, 0x1d, 0x32, 0x1d, 0x32, |
| 597 | 0x02, 0x77, 0x02, 0x09, 0x1e, 0x95, 0x1d, 0x18, 0x1d, 0x32, 0x1e, 0x71, |
| 598 | 0x02, 0x09, 0x1d, 0x32, 0x1e, 0x71, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x09, |
| 599 | 0x1c, 0x7a, 0x1d, 0xdd, 0x1d, 0xaa, 0x1d, 0xaa, 0x1d, 0xdd, 0x1d, 0xb9, |
| 600 | 0x02, 0x09, 0x1e, 0x71, 0x1e, 0x0c, 0x1c, 0xaa, 0x1c, 0x7a, 0x1d, 0x32, |
| 601 | 0x1c, 0x47, 0x1d, 0x77, 0x02, 0x09, 0x1c, 0x7a, 0x1c, 0x47, 0x1e, 0x71, |
| 602 | 0x1c, 0xaa, 0x02, 0x09, 0x1e, 0x95, 0x1d, 0x18, 0x1c, 0x47, 0x1e, 0x95, |
| 603 | 0x02, 0x09, 0x1e, 0xf5, 0x1c, 0x47, 0x1e, 0x33, 0x1e, 0x33, 0x1c, 0x47, |
| 604 | 0x1d, 0xb9, 0x1e, 0x95, 0x1e, 0x71, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x09, |
| 605 | 0x1c, 0x60, 0x1c, 0xaa, 0x1d, 0xb9, 0x1c, 0x7a, 0x1d, 0x18, 0x1d, 0xaa, |
| 606 | 0x1c, 0x47, 0x1e, 0x33, 0x1d, 0x65, 0x02, 0x09, 0x1d, 0xdd, 0x1d, 0xb9, |
| 607 | 0x02, 0x09, 0x1d, 0x32, 0x1e, 0x95, 0x1e, 0x71, 0x02, 0x09, 0x1d, 0xdd, |
| 608 | 0x1e, 0xf5, 0x1d, 0xb9, 0x02, 0x22, 0x02, 0x09, 0x1c, 0xaa, 0x1e, 0xe3, |
| 609 | 0x1c, 0xaa, 0x1d, 0xb9, 0x02, 0x09, 0x1d, 0x32, 0x1c, 0xe5, 0x02, 0x09, |
| 610 | 0x1e, 0x95, 0x1d, 0x18, 0x1c, 0xaa, 0x02, 0x09, 0x1c, 0x7a, 0x1d, 0x18, |
| 611 | 0x1c, 0x47, 0x1e, 0x33, 0x1c, 0x47, 0x1c, 0x7a, 0x1e, 0x95, 0x1c, 0xaa, |
| 612 | 0x1e, 0x33, 0x02, 0x09, 0x1e, 0x71, 0x1c, 0xaa, 0x1e, 0x95, 0x02, 0x09, |
| 613 | 0x1c, 0x47, 0x1d, 0xb9, 0x1c, 0x8f, 0x02, 0x09, 0x1c, 0x7a, 0x1d, 0xdd, |
| 614 | 0x1d, 0x77, 0x1d, 0x77, 0x1c, 0x47, 0x1e, 0x95, 0x1d, 0x32, 0x1d, 0xdd, |
| 615 | 0x1d, 0xb9, 0x02, 0x09, 0x1e, 0x71, 0x1e, 0xb5, 0x1e, 0x0c, 0x1e, 0x0c, |
| 616 | 0x1d, 0xdd, 0x1e, 0x33, 0x1e, 0x95, 0x1e, 0x71, 0x02, 0x09, 0x1d, 0xaa, |
| 617 | 0x1e, 0xb5, 0x1c, 0x7a, 0x1d, 0x18, 0x02, 0x09, 0x1d, 0xaa, 0x1d, 0xdd, |
| 618 | 0x1e, 0x33, 0x1c, 0xaa, 0x02, 0x09, 0x1c, 0x7a, 0x1d, 0xdd, 0x1d, 0xaa, |
| 619 | 0x1e, 0x0c, 0x1d, 0x77, 0x1d, 0x32, 0x1c, 0x7a, 0x1c, 0x47, 0x1e, 0x95, |
| 620 | 0x1c, 0xaa, 0x1c, 0x8f, 0x02, 0x09, 0x1e, 0x71, 0x1c, 0x7a, 0x1c, 0xaa, |
| 621 | 0x1d, 0xb9, 0x1c, 0x47, 0x1e, 0x33, 0x1d, 0x32, 0x1d, 0xdd, 0x1e, 0x71, |
| 622 | 0x02, 0x77}; |
| 623 | uchar dest[sizeof(expected)]; |
| 624 | |
| 625 | StartBenchmarkTiming(); |
| 626 | for (size_t i = 0; i < num_iterations; ++i) { |
| 627 | my_strnxfrm(cs, dest, sizeof(dest), |
| 628 | reinterpret_cast<const uchar *>(content), len); |
| 629 | } |
| 630 | StopBenchmarkTiming(); |
| 631 | |
| 632 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 633 | |
| 634 | SetBytesProcessed(num_iterations * strlen(content)); |
| 635 | } |
| 636 | BENCHMARK(BM_SimpleUTF8MB4) |
| 637 | |
| 638 | // Benchmark testing a wider variety of character sets on a more complicated |
| 639 | // collation (the recommended default collation for 8.0), without stressing |
| 640 | // padding as much. |
| 641 | static void BM_MixedUTF8MB4(size_t num_iterations) { |
| 642 | StopBenchmarkTiming(); |
| 643 | |
| 644 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 645 | |
| 646 | // Some English text, then some Norwegian text, then some Japanese, |
| 647 | // and then a few emoji (the last with skin tone modifiers). |
| 648 | const char *content = |
| 649 | "Premature optimization is the root of all evil. " |
| 650 | "Våre norske tegn bør æres. 日本語が少しわかります。 " |
| 651 | "✌️🐶👩🏽"; |
| 652 | const int len = strlen(content); |
| 653 | |
| 654 | // Just recorded from a trial run on the string above. |
| 655 | static constexpr uchar expected[] = { |
| 656 | 0x1e, 0x0c, 0x1e, 0x33, 0x1c, 0xaa, 0x1d, 0xaa, 0x1c, 0x47, 0x1e, 0x95, |
| 657 | 0x1e, 0xb5, 0x1e, 0x33, 0x1c, 0xaa, 0x02, 0x09, 0x1d, 0xdd, 0x1e, 0x0c, |
| 658 | 0x1e, 0x95, 0x1d, 0x32, 0x1d, 0xaa, 0x1d, 0x32, 0x1f, 0x21, 0x1c, 0x47, |
| 659 | 0x1e, 0x95, 0x1d, 0x32, 0x1d, 0xdd, 0x1d, 0xb9, 0x02, 0x09, 0x1d, 0x32, |
| 660 | 0x1e, 0x71, 0x02, 0x09, 0x1e, 0x95, 0x1d, 0x18, 0x1c, 0xaa, 0x02, 0x09, |
| 661 | 0x1e, 0x33, 0x1d, 0xdd, 0x1d, 0xdd, 0x1e, 0x95, 0x02, 0x09, 0x1d, 0xdd, |
| 662 | 0x1c, 0xe5, 0x02, 0x09, 0x1c, 0x47, 0x1d, 0x77, 0x1d, 0x77, 0x02, 0x09, |
| 663 | 0x1c, 0xaa, 0x1e, 0xe3, 0x1d, 0x32, 0x1d, 0x77, 0x02, 0x77, 0x02, 0x09, |
| 664 | 0x1e, 0xe3, 0x1c, 0x47, 0x1e, 0x33, 0x1c, 0xaa, 0x02, 0x09, 0x1d, 0xb9, |
| 665 | 0x1d, 0xdd, 0x1e, 0x33, 0x1e, 0x71, 0x1d, 0x65, 0x1c, 0xaa, 0x02, 0x09, |
| 666 | 0x1e, 0x95, 0x1c, 0xaa, 0x1c, 0xf4, 0x1d, 0xb9, 0x02, 0x09, 0x1c, 0x60, |
| 667 | 0x1d, 0xdd, 0x1e, 0x33, 0x02, 0x09, 0x1c, 0x47, 0x1c, 0xaa, 0x1e, 0x33, |
| 668 | 0x1c, 0xaa, 0x1e, 0x71, 0x02, 0x77, 0x02, 0x09, 0xfb, 0x40, 0xe5, 0xe5, |
| 669 | 0xfb, 0x40, 0xe7, 0x2c, 0xfb, 0x41, 0x8a, 0x9e, 0x3d, 0x60, 0xfb, 0x40, |
| 670 | 0xdc, 0x11, 0x3d, 0x66, 0x3d, 0x87, 0x3d, 0x60, 0x3d, 0x83, 0x3d, 0x79, |
| 671 | 0x3d, 0x67, 0x02, 0x8a, 0x02, 0x09, 0x0a, 0x2d, 0x13, 0xdf, 0x14, 0x12, |
| 672 | 0x13, 0xa6}; |
| 673 | uchar dest[sizeof(expected)]; |
| 674 | |
| 675 | StartBenchmarkTiming(); |
| 676 | for (size_t i = 0; i < num_iterations; ++i) { |
| 677 | my_strnxfrm(cs, dest, sizeof(dest), |
| 678 | reinterpret_cast<const uchar *>(content), len); |
| 679 | } |
| 680 | StopBenchmarkTiming(); |
| 681 | |
| 682 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 683 | SetBytesProcessed(num_iterations * strlen(content)); |
| 684 | } |
| 685 | BENCHMARK(BM_MixedUTF8MB4) |
| 686 | |
| 687 | static void BM_MixedUTF8MB4_AS_CI(size_t num_iterations) { |
| 688 | StopBenchmarkTiming(); |
| 689 | |
| 690 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_as_ci"); |
| 691 | |
| 692 | // Some English text, then some Norwegian text, then some Japanese, |
| 693 | // and then a few emoji (the last with skin tone modifiers). |
| 694 | const char *content = |
| 695 | "Premature optimization is the root of all evil. " |
| 696 | "Våre norske tegn bør æres. 日本語が少しわかります。 " |
| 697 | "✌️🐶👩🏽"; |
| 698 | const int len = strlen(content); |
| 699 | |
| 700 | // Just recorded from a trial run on the string above. |
| 701 | static constexpr uchar expected[] = { |
| 702 | 0x1e, 0x0c, 0x1e, 0x33, 0x1c, 0xaa, 0x1d, 0xaa, 0x1c, 0x47, 0x1e, 0x95, |
| 703 | 0x1e, 0xb5, 0x1e, 0x33, 0x1c, 0xaa, 0x02, 0x09, 0x1d, 0xdd, 0x1e, 0x0c, |
| 704 | 0x1e, 0x95, 0x1d, 0x32, 0x1d, 0xaa, 0x1d, 0x32, 0x1f, 0x21, 0x1c, 0x47, |
| 705 | 0x1e, 0x95, 0x1d, 0x32, 0x1d, 0xdd, 0x1d, 0xb9, 0x02, 0x09, 0x1d, 0x32, |
| 706 | 0x1e, 0x71, 0x02, 0x09, 0x1e, 0x95, 0x1d, 0x18, 0x1c, 0xaa, 0x02, 0x09, |
| 707 | 0x1e, 0x33, 0x1d, 0xdd, 0x1d, 0xdd, 0x1e, 0x95, 0x02, 0x09, 0x1d, 0xdd, |
| 708 | 0x1c, 0xe5, 0x02, 0x09, 0x1c, 0x47, 0x1d, 0x77, 0x1d, 0x77, 0x02, 0x09, |
| 709 | 0x1c, 0xaa, 0x1e, 0xe3, 0x1d, 0x32, 0x1d, 0x77, 0x02, 0x77, 0x02, 0x09, |
| 710 | 0x1e, 0xe3, 0x1c, 0x47, 0x1e, 0x33, 0x1c, 0xaa, 0x02, 0x09, 0x1d, 0xb9, |
| 711 | 0x1d, 0xdd, 0x1e, 0x33, 0x1e, 0x71, 0x1d, 0x65, 0x1c, 0xaa, 0x02, 0x09, |
| 712 | 0x1e, 0x95, 0x1c, 0xaa, 0x1c, 0xf4, 0x1d, 0xb9, 0x02, 0x09, 0x1c, 0x60, |
| 713 | 0x1d, 0xdd, 0x1e, 0x33, 0x02, 0x09, 0x1c, 0x47, 0x1c, 0xaa, 0x1e, 0x33, |
| 714 | 0x1c, 0xaa, 0x1e, 0x71, 0x02, 0x77, 0x02, 0x09, 0xfb, 0x40, 0xe5, 0xe5, |
| 715 | 0xfb, 0x40, 0xe7, 0x2c, 0xfb, 0x41, 0x8a, 0x9e, 0x3d, 0x60, 0xfb, 0x40, |
| 716 | 0xdc, 0x11, 0x3d, 0x66, 0x3d, 0x87, 0x3d, 0x60, 0x3d, 0x83, 0x3d, 0x79, |
| 717 | 0x3d, 0x67, 0x02, 0x8a, 0x02, 0x09, 0x0a, 0x2d, 0x13, 0xdf, 0x14, 0x12, |
| 718 | 0x13, 0xa6, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 719 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 720 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 721 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 722 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 723 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 724 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 725 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 726 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x29, 0x00, 0x20, |
| 727 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 728 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 729 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x2F, 0x00, 0x20, |
| 730 | 0x00, 0x20, 0x00, 0x20, 0x01, 0x10, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 731 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 732 | 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 733 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 734 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20}; |
| 735 | uchar dest[sizeof(expected)]; |
| 736 | |
| 737 | StartBenchmarkTiming(); |
| 738 | for (size_t i = 0; i < num_iterations; ++i) { |
| 739 | my_strnxfrm(cs, dest, sizeof(dest), |
| 740 | reinterpret_cast<const uchar *>(content), len); |
| 741 | } |
| 742 | StopBenchmarkTiming(); |
| 743 | |
| 744 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 745 | SetBytesProcessed(num_iterations * strlen(content)); |
| 746 | } |
| 747 | BENCHMARK(BM_MixedUTF8MB4_AS_CI) |
| 748 | |
| 749 | // Case-sensitive, accent-sensitive benchmark, using the same string as |
| 750 | // BM_SimpleUTF8MB4. This will naturally be slower, since many more weights |
| 751 | // need to be generated. |
| 752 | static void BM_MixedUTF8MB4_AS_CS(size_t num_iterations) { |
| 753 | StopBenchmarkTiming(); |
| 754 | |
| 755 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_as_cs"); |
| 756 | |
| 757 | // Some English text, then some Norwegian text, then some Japanese, |
| 758 | // and then a few emoji (the last with skin tone modifiers). |
| 759 | const char *content = |
| 760 | "Premature optimization is the root of all evil. " |
| 761 | "Våre norske tegn bør æres. 日本語が少しわかります。 " |
| 762 | "✌️🐶👩🏽"; |
| 763 | const int len = strlen(content); |
| 764 | |
| 765 | // Just recorded from a trial run on the string above. |
| 766 | static constexpr uchar expected[] = { |
| 767 | // Primary weights. |
| 768 | 0x1e, |
| 769 | 0x0c, |
| 770 | 0x1e, |
| 771 | 0x33, |
| 772 | 0x1c, |
| 773 | 0xaa, |
| 774 | 0x1d, |
| 775 | 0xaa, |
| 776 | 0x1c, |
| 777 | 0x47, |
| 778 | 0x1e, |
| 779 | 0x95, |
| 780 | 0x1e, |
| 781 | 0xb5, |
| 782 | 0x1e, |
| 783 | 0x33, |
| 784 | 0x1c, |
| 785 | 0xaa, |
| 786 | 0x02, |
| 787 | 0x09, |
| 788 | 0x1d, |
| 789 | 0xdd, |
| 790 | 0x1e, |
| 791 | 0x0c, |
| 792 | 0x1e, |
| 793 | 0x95, |
| 794 | 0x1d, |
| 795 | 0x32, |
| 796 | 0x1d, |
| 797 | 0xaa, |
| 798 | 0x1d, |
| 799 | 0x32, |
| 800 | 0x1f, |
| 801 | 0x21, |
| 802 | 0x1c, |
| 803 | 0x47, |
| 804 | 0x1e, |
| 805 | 0x95, |
| 806 | 0x1d, |
| 807 | 0x32, |
| 808 | 0x1d, |
| 809 | 0xdd, |
| 810 | 0x1d, |
| 811 | 0xb9, |
| 812 | 0x02, |
| 813 | 0x09, |
| 814 | 0x1d, |
| 815 | 0x32, |
| 816 | 0x1e, |
| 817 | 0x71, |
| 818 | 0x02, |
| 819 | 0x09, |
| 820 | 0x1e, |
| 821 | 0x95, |
| 822 | 0x1d, |
| 823 | 0x18, |
| 824 | 0x1c, |
| 825 | 0xaa, |
| 826 | 0x02, |
| 827 | 0x09, |
| 828 | 0x1e, |
| 829 | 0x33, |
| 830 | 0x1d, |
| 831 | 0xdd, |
| 832 | 0x1d, |
| 833 | 0xdd, |
| 834 | 0x1e, |
| 835 | 0x95, |
| 836 | 0x02, |
| 837 | 0x09, |
| 838 | 0x1d, |
| 839 | 0xdd, |
| 840 | 0x1c, |
| 841 | 0xe5, |
| 842 | 0x02, |
| 843 | 0x09, |
| 844 | 0x1c, |
| 845 | 0x47, |
| 846 | 0x1d, |
| 847 | 0x77, |
| 848 | 0x1d, |
| 849 | 0x77, |
| 850 | 0x02, |
| 851 | 0x09, |
| 852 | 0x1c, |
| 853 | 0xaa, |
| 854 | 0x1e, |
| 855 | 0xe3, |
| 856 | 0x1d, |
| 857 | 0x32, |
| 858 | 0x1d, |
| 859 | 0x77, |
| 860 | 0x02, |
| 861 | 0x77, |
| 862 | 0x02, |
| 863 | 0x09, |
| 864 | 0x1e, |
| 865 | 0xe3, |
| 866 | 0x1c, |
| 867 | 0x47, |
| 868 | 0x1e, |
| 869 | 0x33, |
| 870 | 0x1c, |
| 871 | 0xaa, |
| 872 | 0x02, |
| 873 | 0x09, |
| 874 | 0x1d, |
| 875 | 0xb9, |
| 876 | 0x1d, |
| 877 | 0xdd, |
| 878 | 0x1e, |
| 879 | 0x33, |
| 880 | 0x1e, |
| 881 | 0x71, |
| 882 | 0x1d, |
| 883 | 0x65, |
| 884 | 0x1c, |
| 885 | 0xaa, |
| 886 | 0x02, |
| 887 | 0x09, |
| 888 | 0x1e, |
| 889 | 0x95, |
| 890 | 0x1c, |
| 891 | 0xaa, |
| 892 | 0x1c, |
| 893 | 0xf4, |
| 894 | 0x1d, |
| 895 | 0xb9, |
| 896 | 0x02, |
| 897 | 0x09, |
| 898 | 0x1c, |
| 899 | 0x60, |
| 900 | 0x1d, |
| 901 | 0xdd, |
| 902 | 0x1e, |
| 903 | 0x33, |
| 904 | 0x02, |
| 905 | 0x09, |
| 906 | 0x1c, |
| 907 | 0x47, |
| 908 | 0x1c, |
| 909 | 0xaa, |
| 910 | 0x1e, |
| 911 | 0x33, |
| 912 | 0x1c, |
| 913 | 0xaa, |
| 914 | 0x1e, |
| 915 | 0x71, |
| 916 | 0x02, |
| 917 | 0x77, |
| 918 | 0x02, |
| 919 | 0x09, |
| 920 | 0xfb, |
| 921 | 0x40, |
| 922 | 0xe5, |
| 923 | 0xe5, |
| 924 | 0xfb, |
| 925 | 0x40, |
| 926 | 0xe7, |
| 927 | 0x2c, |
| 928 | 0xfb, |
| 929 | 0x41, |
| 930 | 0x8a, |
| 931 | 0x9e, |
| 932 | 0x3d, |
| 933 | 0x60, |
| 934 | 0xfb, |
| 935 | 0x40, |
| 936 | 0xdc, |
| 937 | 0x11, |
| 938 | 0x3d, |
| 939 | 0x66, |
| 940 | 0x3d, |
| 941 | 0x87, |
| 942 | 0x3d, |
| 943 | 0x60, |
| 944 | 0x3d, |
| 945 | 0x83, |
| 946 | 0x3d, |
| 947 | 0x79, |
| 948 | 0x3d, |
| 949 | 0x67, |
| 950 | 0x02, |
| 951 | 0x8a, |
| 952 | 0x02, |
| 953 | 0x09, |
| 954 | 0x0a, |
| 955 | 0x2d, |
| 956 | 0x13, |
| 957 | 0xdf, |
| 958 | 0x14, |
| 959 | 0x12, |
| 960 | 0x13, |
| 961 | 0xa6, |
| 962 | // Level separator. |
| 963 | 0x00, |
| 964 | 0x00, |
| 965 | // Secondary weights. |
| 966 | 0x00, |
| 967 | 0x20, |
| 968 | 0x00, |
| 969 | 0x20, |
| 970 | 0x00, |
| 971 | 0x20, |
| 972 | 0x00, |
| 973 | 0x20, |
| 974 | 0x00, |
| 975 | 0x20, |
| 976 | 0x00, |
| 977 | 0x20, |
| 978 | 0x00, |
| 979 | 0x20, |
| 980 | 0x00, |
| 981 | 0x20, |
| 982 | 0x00, |
| 983 | 0x20, |
| 984 | 0x00, |
| 985 | 0x20, |
| 986 | 0x00, |
| 987 | 0x20, |
| 988 | 0x00, |
| 989 | 0x20, |
| 990 | 0x00, |
| 991 | 0x20, |
| 992 | 0x00, |
| 993 | 0x20, |
| 994 | 0x00, |
| 995 | 0x20, |
| 996 | 0x00, |
| 997 | 0x20, |
| 998 | 0x00, |
| 999 | 0x20, |
| 1000 | 0x00, |
| 1001 | 0x20, |
| 1002 | 0x00, |
| 1003 | 0x20, |
| 1004 | 0x00, |
| 1005 | 0x20, |
| 1006 | 0x00, |
| 1007 | 0x20, |
| 1008 | 0x00, |
| 1009 | 0x20, |
| 1010 | 0x00, |
| 1011 | 0x20, |
| 1012 | 0x00, |
| 1013 | 0x20, |
| 1014 | 0x00, |
| 1015 | 0x20, |
| 1016 | 0x00, |
| 1017 | 0x20, |
| 1018 | 0x00, |
| 1019 | 0x20, |
| 1020 | 0x00, |
| 1021 | 0x20, |
| 1022 | 0x00, |
| 1023 | 0x20, |
| 1024 | 0x00, |
| 1025 | 0x20, |
| 1026 | 0x00, |
| 1027 | 0x20, |
| 1028 | 0x00, |
| 1029 | 0x20, |
| 1030 | 0x00, |
| 1031 | 0x20, |
| 1032 | 0x00, |
| 1033 | 0x20, |
| 1034 | 0x00, |
| 1035 | 0x20, |
| 1036 | 0x00, |
| 1037 | 0x20, |
| 1038 | 0x00, |
| 1039 | 0x20, |
| 1040 | 0x00, |
| 1041 | 0x20, |
| 1042 | 0x00, |
| 1043 | 0x20, |
| 1044 | 0x00, |
| 1045 | 0x20, |
| 1046 | 0x00, |
| 1047 | 0x20, |
| 1048 | 0x00, |
| 1049 | 0x20, |
| 1050 | 0x00, |
| 1051 | 0x20, |
| 1052 | 0x00, |
| 1053 | 0x20, |
| 1054 | 0x00, |
| 1055 | 0x20, |
| 1056 | 0x00, |
| 1057 | 0x20, |
| 1058 | 0x00, |
| 1059 | 0x20, |
| 1060 | 0x00, |
| 1061 | 0x20, |
| 1062 | 0x00, |
| 1063 | 0x20, |
| 1064 | 0x00, |
| 1065 | 0x20, |
| 1066 | 0x00, |
| 1067 | 0x29, |
| 1068 | 0x00, |
| 1069 | 0x20, |
| 1070 | 0x00, |
| 1071 | 0x20, |
| 1072 | 0x00, |
| 1073 | 0x20, |
| 1074 | 0x00, |
| 1075 | 0x20, |
| 1076 | 0x00, |
| 1077 | 0x20, |
| 1078 | 0x00, |
| 1079 | 0x20, |
| 1080 | 0x00, |
| 1081 | 0x20, |
| 1082 | 0x00, |
| 1083 | 0x20, |
| 1084 | 0x00, |
| 1085 | 0x20, |
| 1086 | 0x00, |
| 1087 | 0x20, |
| 1088 | 0x00, |
| 1089 | 0x20, |
| 1090 | 0x00, |
| 1091 | 0x20, |
| 1092 | 0x00, |
| 1093 | 0x20, |
| 1094 | 0x00, |
| 1095 | 0x20, |
| 1096 | 0x00, |
| 1097 | 0x20, |
| 1098 | 0x00, |
| 1099 | 0x20, |
| 1100 | 0x00, |
| 1101 | 0x20, |
| 1102 | 0x00, |
| 1103 | 0x2f, |
| 1104 | 0x00, |
| 1105 | 0x20, |
| 1106 | 0x00, |
| 1107 | 0x20, |
| 1108 | 0x00, |
| 1109 | 0x20, |
| 1110 | 0x01, |
| 1111 | 0x10, |
| 1112 | 0x00, |
| 1113 | 0x20, |
| 1114 | 0x00, |
| 1115 | 0x20, |
| 1116 | 0x00, |
| 1117 | 0x20, |
| 1118 | 0x00, |
| 1119 | 0x20, |
| 1120 | 0x00, |
| 1121 | 0x20, |
| 1122 | 0x00, |
| 1123 | 0x20, |
| 1124 | 0x00, |
| 1125 | 0x20, |
| 1126 | 0x00, |
| 1127 | 0x20, |
| 1128 | 0x00, |
| 1129 | 0x20, |
| 1130 | 0x00, |
| 1131 | 0x20, |
| 1132 | 0x00, |
| 1133 | 0x37, |
| 1134 | 0x00, |
| 1135 | 0x20, |
| 1136 | 0x00, |
| 1137 | 0x20, |
| 1138 | 0x00, |
| 1139 | 0x20, |
| 1140 | 0x00, |
| 1141 | 0x20, |
| 1142 | 0x00, |
| 1143 | 0x20, |
| 1144 | 0x00, |
| 1145 | 0x20, |
| 1146 | 0x00, |
| 1147 | 0x20, |
| 1148 | 0x00, |
| 1149 | 0x20, |
| 1150 | 0x00, |
| 1151 | 0x20, |
| 1152 | 0x00, |
| 1153 | 0x20, |
| 1154 | 0x00, |
| 1155 | 0x20, |
| 1156 | 0x00, |
| 1157 | 0x20, |
| 1158 | 0x00, |
| 1159 | 0x20, |
| 1160 | // Level separator. |
| 1161 | 0x00, |
| 1162 | 0x00, |
| 1163 | // Tertiary weights. |
| 1164 | 0x00, |
| 1165 | 0x08, |
| 1166 | 0x00, |
| 1167 | 0x02, |
| 1168 | 0x00, |
| 1169 | 0x02, |
| 1170 | 0x00, |
| 1171 | 0x02, |
| 1172 | 0x00, |
| 1173 | 0x02, |
| 1174 | 0x00, |
| 1175 | 0x02, |
| 1176 | 0x00, |
| 1177 | 0x02, |
| 1178 | 0x00, |
| 1179 | 0x02, |
| 1180 | 0x00, |
| 1181 | 0x02, |
| 1182 | 0x00, |
| 1183 | 0x02, |
| 1184 | 0x00, |
| 1185 | 0x02, |
| 1186 | 0x00, |
| 1187 | 0x02, |
| 1188 | 0x00, |
| 1189 | 0x02, |
| 1190 | 0x00, |
| 1191 | 0x02, |
| 1192 | 0x00, |
| 1193 | 0x02, |
| 1194 | 0x00, |
| 1195 | 0x02, |
| 1196 | 0x00, |
| 1197 | 0x02, |
| 1198 | 0x00, |
| 1199 | 0x02, |
| 1200 | 0x00, |
| 1201 | 0x02, |
| 1202 | 0x00, |
| 1203 | 0x02, |
| 1204 | 0x00, |
| 1205 | 0x02, |
| 1206 | 0x00, |
| 1207 | 0x02, |
| 1208 | 0x00, |
| 1209 | 0x02, |
| 1210 | 0x00, |
| 1211 | 0x02, |
| 1212 | 0x00, |
| 1213 | 0x02, |
| 1214 | 0x00, |
| 1215 | 0x02, |
| 1216 | 0x00, |
| 1217 | 0x02, |
| 1218 | 0x00, |
| 1219 | 0x02, |
| 1220 | 0x00, |
| 1221 | 0x02, |
| 1222 | 0x00, |
| 1223 | 0x02, |
| 1224 | 0x00, |
| 1225 | 0x02, |
| 1226 | 0x00, |
| 1227 | 0x02, |
| 1228 | 0x00, |
| 1229 | 0x02, |
| 1230 | 0x00, |
| 1231 | 0x02, |
| 1232 | 0x00, |
| 1233 | 0x02, |
| 1234 | 0x00, |
| 1235 | 0x02, |
| 1236 | 0x00, |
| 1237 | 0x02, |
| 1238 | 0x00, |
| 1239 | 0x02, |
| 1240 | 0x00, |
| 1241 | 0x02, |
| 1242 | 0x00, |
| 1243 | 0x02, |
| 1244 | 0x00, |
| 1245 | 0x02, |
| 1246 | 0x00, |
| 1247 | 0x02, |
| 1248 | 0x00, |
| 1249 | 0x02, |
| 1250 | 0x00, |
| 1251 | 0x02, |
| 1252 | 0x00, |
| 1253 | 0x02, |
| 1254 | 0x00, |
| 1255 | 0x02, |
| 1256 | 0x00, |
| 1257 | 0x02, |
| 1258 | 0x00, |
| 1259 | 0x02, |
| 1260 | 0x00, |
| 1261 | 0x08, |
| 1262 | 0x00, |
| 1263 | 0x02, |
| 1264 | 0x00, |
| 1265 | 0x02, |
| 1266 | 0x00, |
| 1267 | 0x02, |
| 1268 | 0x00, |
| 1269 | 0x02, |
| 1270 | 0x00, |
| 1271 | 0x02, |
| 1272 | 0x00, |
| 1273 | 0x02, |
| 1274 | 0x00, |
| 1275 | 0x02, |
| 1276 | 0x00, |
| 1277 | 0x02, |
| 1278 | 0x00, |
| 1279 | 0x02, |
| 1280 | 0x00, |
| 1281 | 0x02, |
| 1282 | 0x00, |
| 1283 | 0x02, |
| 1284 | 0x00, |
| 1285 | 0x02, |
| 1286 | 0x00, |
| 1287 | 0x02, |
| 1288 | 0x00, |
| 1289 | 0x02, |
| 1290 | 0x00, |
| 1291 | 0x02, |
| 1292 | 0x00, |
| 1293 | 0x02, |
| 1294 | 0x00, |
| 1295 | 0x02, |
| 1296 | 0x00, |
| 1297 | 0x02, |
| 1298 | 0x00, |
| 1299 | 0x02, |
| 1300 | 0x00, |
| 1301 | 0x02, |
| 1302 | 0x00, |
| 1303 | 0x02, |
| 1304 | 0x00, |
| 1305 | 0x02, |
| 1306 | 0x00, |
| 1307 | 0x04, |
| 1308 | 0x00, |
| 1309 | 0x04, |
| 1310 | 0x00, |
| 1311 | 0x04, |
| 1312 | 0x00, |
| 1313 | 0x02, |
| 1314 | 0x00, |
| 1315 | 0x02, |
| 1316 | 0x00, |
| 1317 | 0x02, |
| 1318 | 0x00, |
| 1319 | 0x02, |
| 1320 | 0x00, |
| 1321 | 0x02, |
| 1322 | 0x00, |
| 1323 | 0x02, |
| 1324 | 0x00, |
| 1325 | 0x02, |
| 1326 | 0x00, |
| 1327 | 0x02, |
| 1328 | 0x00, |
| 1329 | 0x0e, |
| 1330 | 0x00, |
| 1331 | 0x02, |
| 1332 | 0x00, |
| 1333 | 0x02, |
| 1334 | 0x00, |
| 1335 | 0x0e, |
| 1336 | 0x00, |
| 1337 | 0x0e, |
| 1338 | 0x00, |
| 1339 | 0x0e, |
| 1340 | 0x00, |
| 1341 | 0x0e, |
| 1342 | 0x00, |
| 1343 | 0x0e, |
| 1344 | 0x00, |
| 1345 | 0x0e, |
| 1346 | 0x00, |
| 1347 | 0x02, |
| 1348 | 0x00, |
| 1349 | 0x02, |
| 1350 | 0x00, |
| 1351 | 0x02, |
| 1352 | 0x00, |
| 1353 | 0x02, |
| 1354 | 0x00, |
| 1355 | 0x02, |
| 1356 | 0x00, |
| 1357 | 0x02, |
| 1358 | }; |
| 1359 | uchar dest[sizeof(expected)]; |
| 1360 | |
| 1361 | size_t ret = 0; |
| 1362 | StartBenchmarkTiming(); |
| 1363 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1364 | ret = my_strnxfrm(cs, dest, sizeof(dest), |
| 1365 | pointer_cast<const uchar *>(content), len); |
| 1366 | } |
| 1367 | StopBenchmarkTiming(); |
| 1368 | |
| 1369 | EXPECT_EQ(sizeof(expected), ret); |
| 1370 | expect_arrays_equal(expected, dest, ret); |
| 1371 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1372 | } |
| 1373 | BENCHMARK(BM_MixedUTF8MB4_AS_CS) |
| 1374 | |
| 1375 | // Specifically benchmark Japanese text. |
| 1376 | static void BM_JapaneseUTF8MB4(size_t num_iterations) { |
| 1377 | StopBenchmarkTiming(); |
| 1378 | |
| 1379 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 1380 | const char *content = |
| 1381 | "データの保存とアクセスを行うストレージエンジンがSQLパーサとは" |
| 1382 | "分離独立しており、用途に応じたストレージエンジンを選択できる" |
| 1383 | "「マルチストレージエンジン」方式を採用している。"; |
| 1384 | const int len = strlen(content); |
| 1385 | |
| 1386 | // Just recorded from a trial run on the string above. |
| 1387 | static constexpr uchar expected[] = { |
| 1388 | 0x3d, 0x6d, 0x1c, 0x0e, 0x3d, 0x6a, 0x3d, 0x73, 0xfb, 0x40, 0xcf, 0xdd, |
| 1389 | 0xfb, 0x40, 0xdb, 0x58, 0x3d, 0x6e, 0x3d, 0x5a, 0x3d, 0x62, 0x3d, 0x68, |
| 1390 | 0x3d, 0x67, 0x3d, 0x8a, 0xfb, 0x41, 0x88, 0x4c, 0x3d, 0x5c, 0x3d, 0x67, |
| 1391 | 0x3d, 0x6e, 0x3d, 0x85, 0x1c, 0x0e, 0x3d, 0x66, 0x3d, 0x5e, 0x3d, 0x8b, |
| 1392 | 0x3d, 0x66, 0x3d, 0x8b, 0x3d, 0x60, 0x1e, 0x71, 0x1e, 0x21, 0x1d, 0x77, |
| 1393 | 0x3d, 0x74, 0x1c, 0x0e, 0x3d, 0x65, 0x3d, 0x6e, 0x3d, 0x74, 0xfb, 0x40, |
| 1394 | 0xd2, 0x06, 0xfb, 0x41, 0x96, 0xe2, 0xfb, 0x40, 0xf2, 0xec, 0xfb, 0x40, |
| 1395 | 0xfa, 0xcb, 0x3d, 0x66, 0x3d, 0x6d, 0x3d, 0x5f, 0x3d, 0x83, 0x02, 0x31, |
| 1396 | 0xfb, 0x40, 0xf5, 0x28, 0xfb, 0x41, 0x90, 0x14, 0x3d, 0x70, 0xfb, 0x40, |
| 1397 | 0xdf, 0xdc, 0x3d, 0x66, 0x3d, 0x6a, 0x3d, 0x67, 0x3d, 0x6e, 0x3d, 0x85, |
| 1398 | 0x1c, 0x0e, 0x3d, 0x66, 0x3d, 0x5e, 0x3d, 0x8b, 0x3d, 0x66, 0x3d, 0x8b, |
| 1399 | 0x3d, 0x8a, 0xfb, 0x41, 0x90, 0x78, 0xfb, 0x40, 0xe2, 0x9e, 0x3d, 0x6d, |
| 1400 | 0x3d, 0x61, 0x3d, 0x84, 0x03, 0x73, 0x3d, 0x79, 0x3d, 0x84, 0x3d, 0x6b, |
| 1401 | 0x3d, 0x67, 0x3d, 0x6e, 0x3d, 0x85, 0x1c, 0x0e, 0x3d, 0x66, 0x3d, 0x5e, |
| 1402 | 0x3d, 0x8b, 0x3d, 0x66, 0x3d, 0x8b, 0x03, 0x74, 0xfb, 0x40, 0xe5, 0xb9, |
| 1403 | 0xfb, 0x40, 0xdf, 0x0f, 0x3d, 0x8a, 0xfb, 0x40, 0xe3, 0xa1, 0xfb, 0x40, |
| 1404 | 0xf5, 0x28, 0x3d, 0x66, 0x3d, 0x6d, 0x3d, 0x5b, 0x3d, 0x84, 0x02, 0x8a}; |
| 1405 | uchar dest[sizeof(expected)]; |
| 1406 | |
| 1407 | StartBenchmarkTiming(); |
| 1408 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1409 | my_strnxfrm(cs, dest, sizeof(dest), |
| 1410 | reinterpret_cast<const uchar *>(content), len); |
| 1411 | } |
| 1412 | StopBenchmarkTiming(); |
| 1413 | |
| 1414 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 1415 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1416 | } |
| 1417 | BENCHMARK(BM_JapaneseUTF8MB4) |
| 1418 | |
| 1419 | /* |
| 1420 | A benchmark that illustrates the potential perils of not including the |
| 1421 | range [0x00,0x20) in our fast path; newlines throw us off the fast path |
| 1422 | and reduce speed. |
| 1423 | |
| 1424 | The newlines are spaced a bit randomly in order not to create a perfectly |
| 1425 | predictable pattern for the branch predictor (benchmark paranoia). |
| 1426 | */ |
| 1427 | static void BM_NewlineFilledUTF8MB4(size_t num_iterations) { |
| 1428 | StopBenchmarkTiming(); |
| 1429 | |
| 1430 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 1431 | |
| 1432 | const char *content = |
| 1433 | "This is a\n prett\ny unrealist\nic case; a\nn " |
| 1434 | "Eng\nlish sente\nnce where\n we'\nve added a new\nline every te\nn " |
| 1435 | "bytes or\n so.\n"; |
| 1436 | const int len = strlen(content); |
| 1437 | |
| 1438 | // Just recorded from a trial run on the string above. |
| 1439 | static constexpr uchar expected[] = { |
| 1440 | 0x1e, 0x95, 0x1d, 0x18, 0x1d, 0x32, 0x1e, 0x71, 0x02, 0x09, 0x1d, 0x32, |
| 1441 | 0x1e, 0x71, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x02, 0x02, 0x09, 0x1e, 0x0c, |
| 1442 | 0x1e, 0x33, 0x1c, 0xaa, 0x1e, 0x95, 0x1e, 0x95, 0x02, 0x02, 0x1f, 0x0b, |
| 1443 | 0x02, 0x09, 0x1e, 0xb5, 0x1d, 0xb9, 0x1e, 0x33, 0x1c, 0xaa, 0x1c, 0x47, |
| 1444 | 0x1d, 0x77, 0x1d, 0x32, 0x1e, 0x71, 0x1e, 0x95, 0x02, 0x02, 0x1d, 0x32, |
| 1445 | 0x1c, 0x7a, 0x02, 0x09, 0x1c, 0x7a, 0x1c, 0x47, 0x1e, 0x71, 0x1c, 0xaa, |
| 1446 | 0x02, 0x34, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x02, 0x1d, 0xb9, 0x02, 0x09, |
| 1447 | 0x1c, 0xaa, 0x1d, 0xb9, 0x1c, 0xf4, 0x02, 0x02, 0x1d, 0x77, 0x1d, 0x32, |
| 1448 | 0x1e, 0x71, 0x1d, 0x18, 0x02, 0x09, 0x1e, 0x71, 0x1c, 0xaa, 0x1d, 0xb9, |
| 1449 | 0x1e, 0x95, 0x1c, 0xaa, 0x02, 0x02, 0x1d, 0xb9, 0x1c, 0x7a, 0x1c, 0xaa, |
| 1450 | 0x02, 0x09, 0x1e, 0xf5, 0x1d, 0x18, 0x1c, 0xaa, 0x1e, 0x33, 0x1c, 0xaa, |
| 1451 | 0x02, 0x02, 0x02, 0x09, 0x1e, 0xf5, 0x1c, 0xaa, 0x03, 0x05, 0x02, 0x02, |
| 1452 | 0x1e, 0xe3, 0x1c, 0xaa, 0x02, 0x09, 0x1c, 0x47, 0x1c, 0x8f, 0x1c, 0x8f, |
| 1453 | 0x1c, 0xaa, 0x1c, 0x8f, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x09, 0x1d, 0xb9, |
| 1454 | 0x1c, 0xaa, 0x1e, 0xf5, 0x02, 0x02, 0x1d, 0x77, 0x1d, 0x32, 0x1d, 0xb9, |
| 1455 | 0x1c, 0xaa, 0x02, 0x09, 0x1c, 0xaa, 0x1e, 0xe3, 0x1c, 0xaa, 0x1e, 0x33, |
| 1456 | 0x1f, 0x0b, 0x02, 0x09, 0x1e, 0x95, 0x1c, 0xaa, 0x02, 0x02, 0x1d, 0xb9, |
| 1457 | 0x02, 0x09, 0x1c, 0x60, 0x1f, 0x0b, 0x1e, 0x95, 0x1c, 0xaa, 0x1e, 0x71, |
| 1458 | 0x02, 0x09, 0x1d, 0xdd, 0x1e, 0x33, 0x02, 0x02, 0x02, 0x09, 0x1e, 0x71, |
| 1459 | 0x1d, 0xdd, 0x02, 0x77, 0x02, 0x02}; |
| 1460 | uchar dest[sizeof(expected)]; |
| 1461 | |
| 1462 | StartBenchmarkTiming(); |
| 1463 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1464 | my_strnxfrm(cs, dest, sizeof(dest), |
| 1465 | reinterpret_cast<const uchar *>(content), len); |
| 1466 | } |
| 1467 | StopBenchmarkTiming(); |
| 1468 | |
| 1469 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 1470 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1471 | } |
| 1472 | BENCHMARK(BM_NewlineFilledUTF8MB4) |
| 1473 | |
| 1474 | static void BM_HashSimpleUTF8MB4(size_t num_iterations) { |
| 1475 | StopBenchmarkTiming(); |
| 1476 | |
| 1477 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 1478 | |
| 1479 | const char *content = |
| 1480 | "This is a rather long string that contains only " |
| 1481 | "simple letters that are available in ASCII. This is a common special " |
| 1482 | "case that warrants a benchmark on its own, even if the character set " |
| 1483 | "and collation supports much more complicated scenarios."; |
| 1484 | const int len = strlen(content); |
| 1485 | |
| 1486 | uint64 nr1 = 1, nr2 = 4; |
| 1487 | |
| 1488 | StartBenchmarkTiming(); |
| 1489 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1490 | cs->coll->hash_sort(cs, reinterpret_cast<const uchar *>(content), len, &nr1, |
| 1491 | &nr2); |
| 1492 | } |
| 1493 | StopBenchmarkTiming(); |
| 1494 | |
| 1495 | /* |
| 1496 | Just to keep the compiler from optimizing away everything; this is highly |
| 1497 | unlikely to ever happen given hash function that's not totally broken. |
| 1498 | Don't test for an exact value; it will vary by platform and number |
| 1499 | of iterations. |
| 1500 | */ |
| 1501 | EXPECT_FALSE(nr1 == 0 && nr2 == 0); |
| 1502 | } |
| 1503 | BENCHMARK(BM_HashSimpleUTF8MB4) |
| 1504 | |
| 1505 | /* |
| 1506 | Test a non-trivial collation with contractions, to highlight |
| 1507 | the performance difference. |
| 1508 | */ |
| 1509 | static void BM_Hungarian_AS_CS(size_t num_iterations) { |
| 1510 | StopBenchmarkTiming(); |
| 1511 | |
| 1512 | CHARSET_INFO *cs = init_collation("utf8mb4_hu_0900_as_cs"); |
| 1513 | |
| 1514 | // Text snippet from Wikipedia. |
| 1515 | const char *content = |
| 1516 | "A MySQL adatbázisok adminisztrációjára a mellékelt " |
| 1517 | "parancssori eszközöket (mysql és mysqladmin) használhatjuk."; |
| 1518 | const int len = strlen(content); |
| 1519 | |
| 1520 | // Just recorded from a trial run on the string above. |
| 1521 | static constexpr uchar expected[] = { |
| 1522 | 0x1c, 0x47, 0x02, 0x09, 0x1d, 0xaa, 0x1f, 0x0b, 0x1e, 0x71, 0x1e, 0x21, |
| 1523 | 0x1d, 0x77, 0x02, 0x09, 0x1c, 0x47, 0x1c, 0x8f, 0x1c, 0x47, 0x1e, 0x95, |
| 1524 | 0x1c, 0x60, 0x1c, 0x47, 0x1f, 0x21, 0x1d, 0x32, 0x1e, 0x71, 0x1d, 0xdd, |
| 1525 | 0x1d, 0x65, 0x02, 0x09, 0x1c, 0x47, 0x1c, 0x8f, 0x1d, 0xaa, 0x1d, 0x32, |
| 1526 | 0x1d, 0xb9, 0x1d, 0x32, 0x1e, 0x71, 0x54, 0xa5, 0x1e, 0x95, 0x1e, 0x33, |
| 1527 | 0x1c, 0x47, 0x1c, 0x7a, 0x1d, 0x32, 0x1d, 0xdd, 0x1d, 0x4c, 0x1c, 0x47, |
| 1528 | 0x1e, 0x33, 0x1c, 0x47, 0x02, 0x09, 0x1c, 0x47, 0x02, 0x09, 0x1d, 0xaa, |
| 1529 | 0x1c, 0xaa, 0x1d, 0x77, 0x1d, 0x77, 0x1c, 0xaa, 0x1d, 0x65, 0x1c, 0xaa, |
| 1530 | 0x1d, 0x77, 0x1e, 0x95, 0x02, 0x09, 0x1e, 0x0c, 0x1c, 0x47, 0x1e, 0x33, |
| 1531 | 0x1c, 0x47, 0x1d, 0xb9, 0x1c, 0x7a, 0x54, 0xa5, 0x1e, 0x71, 0x1d, 0xdd, |
| 1532 | 0x1e, 0x33, 0x1d, 0x32, 0x02, 0x09, 0x1c, 0xaa, 0x1e, 0x71, 0x54, 0xa5, |
| 1533 | 0x1d, 0x65, 0x1d, 0xdd, 0x54, 0xa5, 0x1f, 0x21, 0x1d, 0xdd, 0x54, 0xa5, |
| 1534 | 0x1d, 0x65, 0x1c, 0xaa, 0x1e, 0x95, 0x02, 0x09, 0x03, 0x17, 0x1d, 0xaa, |
| 1535 | 0x1f, 0x0b, 0x1e, 0x71, 0x1e, 0x21, 0x1d, 0x77, 0x02, 0x09, 0x1c, 0xaa, |
| 1536 | 0x1e, 0x71, 0x02, 0x09, 0x1d, 0xaa, 0x1f, 0x0b, 0x1e, 0x71, 0x1e, 0x21, |
| 1537 | 0x1d, 0x77, 0x1c, 0x47, 0x1c, 0x8f, 0x1d, 0xaa, 0x1d, 0x32, 0x1d, 0xb9, |
| 1538 | 0x03, 0x18, 0x02, 0x09, 0x1d, 0x18, 0x1c, 0x47, 0x1e, 0x71, 0x54, 0xa5, |
| 1539 | 0x1d, 0xb9, 0x1c, 0x47, 0x1d, 0x77, 0x1d, 0x18, 0x1c, 0x47, 0x1e, 0x95, |
| 1540 | 0x1d, 0x4c, 0x1e, 0xb5, 0x1d, 0x65, 0x02, 0x77, 0x00, 0x00, 0x00, 0x20, |
| 1541 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1542 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1543 | 0x00, 0x20, 0x00, 0x24, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1544 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1545 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1546 | 0x00, 0x24, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x24, 0x00, 0x20, |
| 1547 | 0x00, 0x20, 0x00, 0x24, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1548 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1549 | 0x00, 0x24, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1550 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1551 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1552 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1553 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1554 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x24, |
| 1555 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1556 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1557 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1558 | 0x00, 0x20, 0x00, 0x24, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1559 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08, |
| 1560 | 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, |
| 1561 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1562 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1563 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1564 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1565 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1566 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1567 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1568 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1569 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, |
| 1570 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1571 | 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, |
| 1572 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1573 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1574 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1575 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1576 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, 0x00, 0x02, |
| 1577 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1578 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02}; |
| 1579 | uchar dest[sizeof(expected)] = {0}; |
| 1580 | |
| 1581 | size_t ret = 0; |
| 1582 | StartBenchmarkTiming(); |
| 1583 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1584 | ret = my_strnxfrm(cs, dest, sizeof(dest), |
| 1585 | pointer_cast<const uchar *>(content), len); |
| 1586 | } |
| 1587 | StopBenchmarkTiming(); |
| 1588 | |
| 1589 | EXPECT_EQ(sizeof(expected), ret); |
| 1590 | expect_arrays_equal(expected, dest, ret); |
| 1591 | |
| 1592 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1593 | } |
| 1594 | BENCHMARK(BM_Hungarian_AS_CS) |
| 1595 | |
| 1596 | static void BM_Japanese_AS_CS(size_t num_iterations) { |
| 1597 | StopBenchmarkTiming(); |
| 1598 | |
| 1599 | CHARSET_INFO *cs = init_collation("utf8mb4_ja_0900_as_cs"); |
| 1600 | const char *content = |
| 1601 | "サーバー SQL モードの設定方法。この設定は、たとえば" |
| 1602 | "別のデータベースシステムからのコードとの互換性を保ったり、特定の状況に" |
| 1603 | "ついてのエラー処理を制御したりするために、SQL の構文およびセマンティクス" |
| 1604 | "の特定の側面を変更します。"; |
| 1605 | const int len = strlen(content); |
| 1606 | |
| 1607 | // Just recorded from a trial run on the string above. |
| 1608 | static constexpr uchar expected[] = { |
| 1609 | 0x1F, 0xC1, 0x1F, 0xB6, 0x1F, 0xD0, 0x1F, 0xB6, 0x02, 0x09, 0x1E, 0x71, |
| 1610 | 0x1E, 0x21, 0x1D, 0x77, 0x02, 0x09, 0x1F, 0xD9, 0x1F, 0xBB, 0x1F, 0xCA, |
| 1611 | 0x1F, 0xCF, 0x5A, 0xC2, 0x5C, 0x45, 0x5E, 0x8C, 0x5E, 0x8E, 0x02, 0x8A, |
| 1612 | 0x1F, 0xC0, 0x1F, 0xCF, 0x5A, 0xC2, 0x5C, 0x45, 0x1F, 0xD0, 0x02, 0x31, |
| 1613 | 0x1F, 0xC6, 0x1F, 0xCA, 0x1F, 0xBA, 0x1F, 0xD0, 0x5E, 0x5B, 0x1F, 0xCF, |
| 1614 | 0x1F, 0xC9, 0x1F, 0xBA, 0x1F, 0xC6, 0x1F, 0xD3, 0x1F, 0xBA, 0x1F, 0xC3, |
| 1615 | 0x1F, 0xC2, 0x1F, 0xC3, 0x1F, 0xC9, 0x1F, 0xD7, 0x1F, 0xBC, 0x1F, 0xDE, |
| 1616 | 0x1F, 0xCF, 0x1F, 0xC0, 0x1F, 0xBB, 0x1F, 0xCA, 0x1F, 0xCA, 0x1F, 0xCF, |
| 1617 | 0x57, 0xD2, 0x56, 0x34, 0x5A, 0x90, 0x1F, 0xE6, 0x5E, 0x6C, 0x1F, 0xC8, |
| 1618 | 0x1F, 0xC6, 0x1F, 0xDF, 0x02, 0x31, 0x5C, 0xDA, 0x5C, 0x45, 0x1F, 0xCF, |
| 1619 | 0x5A, 0x1C, 0x56, 0xEE, 0x1F, 0xCC, 0x1F, 0xC8, 0x1F, 0xB7, 0x1F, 0xC9, |
| 1620 | 0x1F, 0xCF, 0x1F, 0xBA, 0x1F, 0xDE, 0x1F, 0xB6, 0x59, 0xB1, 0x5F, 0xA6, |
| 1621 | 0x1F, 0xE6, 0x5A, 0x8C, 0x57, 0xD9, 0x1F, 0xC2, 0x1F, 0xC6, 0x1F, 0xDF, |
| 1622 | 0x1F, 0xC3, 0x1F, 0xE0, 0x1F, 0xC6, 0x1F, 0xD8, 0x1F, 0xCC, 0x02, 0x31, |
| 1623 | 0x1E, 0x71, 0x1E, 0x21, 0x1D, 0x77, 0x02, 0x09, 0x1F, 0xCF, 0x58, 0x0E, |
| 1624 | 0x5E, 0x47, 0x1F, 0xBB, 0x1F, 0xDD, 0x1F, 0xD1, 0x1F, 0xC4, 0x1F, 0xD5, |
| 1625 | 0x1F, 0xE7, 0x1F, 0xC9, 0x1F, 0xB7, 0x1F, 0xBE, 0x1F, 0xC3, 0x1F, 0xCF, |
| 1626 | 0x5C, 0xDA, 0x5C, 0x45, 0x1F, 0xCF, 0x5B, 0x45, 0x5F, 0x17, 0x1F, 0xE6, |
| 1627 | 0x5E, 0x60, 0x58, 0x0A, 0x1F, 0xC2, 0x1F, 0xD5, 0x1F, 0xC3, 0x02, 0x8A, |
| 1628 | 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, |
| 1629 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1630 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1631 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1632 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1633 | 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, |
| 1634 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, |
| 1635 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1636 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, |
| 1637 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1638 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1639 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1640 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1641 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1642 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1643 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1644 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, |
| 1645 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1646 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1647 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1648 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, |
| 1649 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x21, 0x00, 0x02, 0x00, 0x08, |
| 1650 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, |
| 1651 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1652 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, |
| 1653 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1654 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0C, |
| 1655 | 0x00, 0x21, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x21, |
| 1656 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1657 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, 0x00, 0x0E, |
| 1658 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1659 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, |
| 1660 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, |
| 1661 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1662 | 0x00, 0x0C, 0x00, 0x21, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, |
| 1663 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1664 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x08, 0x00, 0x08, |
| 1665 | 0x00, 0x08, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, |
| 1666 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1667 | 0x00, 0x0E, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, |
| 1668 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, |
| 1669 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02}; |
| 1670 | uchar dest[sizeof(expected)]; |
| 1671 | |
| 1672 | StartBenchmarkTiming(); |
| 1673 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1674 | my_strnxfrm(cs, dest, sizeof(dest), |
| 1675 | reinterpret_cast<const uchar *>(content), len); |
| 1676 | } |
| 1677 | StopBenchmarkTiming(); |
| 1678 | |
| 1679 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 1680 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1681 | } |
| 1682 | BENCHMARK(BM_Japanese_AS_CS) |
| 1683 | |
| 1684 | static void BM_Japanese_AS_CS_KS(size_t num_iterations) { |
| 1685 | StopBenchmarkTiming(); |
| 1686 | |
| 1687 | CHARSET_INFO *cs = init_collation("utf8mb4_ja_0900_as_cs_ks"); |
| 1688 | const char *content = |
| 1689 | "サーバー SQL モードの設定方法。この設定は、たとえば" |
| 1690 | "別のデータベースシステムからのコードとの互換性を保ったり、特定の状況に" |
| 1691 | "ついてのエラー処理を制御したりするために、SQL の構文およびセマンティクス" |
| 1692 | "の特定の側面を変更します。"; |
| 1693 | const int len = strlen(content); |
| 1694 | |
| 1695 | // Just recorded from a trial run on the string above. |
| 1696 | static constexpr uchar expected[] = { |
| 1697 | 0x1F, 0xC1, 0x1F, 0xB6, 0x1F, 0xD0, 0x1F, 0xB6, 0x02, 0x09, 0x1E, 0x71, |
| 1698 | 0x1E, 0x21, 0x1D, 0x77, 0x02, 0x09, 0x1F, 0xD9, 0x1F, 0xBB, 0x1F, 0xCA, |
| 1699 | 0x1F, 0xCF, 0x5A, 0xC2, 0x5C, 0x45, 0x5E, 0x8C, 0x5E, 0x8E, 0x02, 0x8A, |
| 1700 | 0x1F, 0xC0, 0x1F, 0xCF, 0x5A, 0xC2, 0x5C, 0x45, 0x1F, 0xD0, 0x02, 0x31, |
| 1701 | 0x1F, 0xC6, 0x1F, 0xCA, 0x1F, 0xBA, 0x1F, 0xD0, 0x5E, 0x5B, 0x1F, 0xCF, |
| 1702 | 0x1F, 0xC9, 0x1F, 0xBA, 0x1F, 0xC6, 0x1F, 0xD3, 0x1F, 0xBA, 0x1F, 0xC3, |
| 1703 | 0x1F, 0xC2, 0x1F, 0xC3, 0x1F, 0xC9, 0x1F, 0xD7, 0x1F, 0xBC, 0x1F, 0xDE, |
| 1704 | 0x1F, 0xCF, 0x1F, 0xC0, 0x1F, 0xBB, 0x1F, 0xCA, 0x1F, 0xCA, 0x1F, 0xCF, |
| 1705 | 0x57, 0xD2, 0x56, 0x34, 0x5A, 0x90, 0x1F, 0xE6, 0x5E, 0x6C, 0x1F, 0xC8, |
| 1706 | 0x1F, 0xC6, 0x1F, 0xDF, 0x02, 0x31, 0x5C, 0xDA, 0x5C, 0x45, 0x1F, 0xCF, |
| 1707 | 0x5A, 0x1C, 0x56, 0xEE, 0x1F, 0xCC, 0x1F, 0xC8, 0x1F, 0xB7, 0x1F, 0xC9, |
| 1708 | 0x1F, 0xCF, 0x1F, 0xBA, 0x1F, 0xDE, 0x1F, 0xB6, 0x59, 0xB1, 0x5F, 0xA6, |
| 1709 | 0x1F, 0xE6, 0x5A, 0x8C, 0x57, 0xD9, 0x1F, 0xC2, 0x1F, 0xC6, 0x1F, 0xDF, |
| 1710 | 0x1F, 0xC3, 0x1F, 0xE0, 0x1F, 0xC6, 0x1F, 0xD8, 0x1F, 0xCC, 0x02, 0x31, |
| 1711 | 0x1E, 0x71, 0x1E, 0x21, 0x1D, 0x77, 0x02, 0x09, 0x1F, 0xCF, 0x58, 0x0E, |
| 1712 | 0x5E, 0x47, 0x1F, 0xBB, 0x1F, 0xDD, 0x1F, 0xD1, 0x1F, 0xC4, 0x1F, 0xD5, |
| 1713 | 0x1F, 0xE7, 0x1F, 0xC9, 0x1F, 0xB7, 0x1F, 0xBE, 0x1F, 0xC3, 0x1F, 0xCF, |
| 1714 | 0x5C, 0xDA, 0x5C, 0x45, 0x1F, 0xCF, 0x5B, 0x45, 0x5F, 0x17, 0x1F, 0xE6, |
| 1715 | 0x5E, 0x60, 0x58, 0x0A, 0x1F, 0xC2, 0x1F, 0xD5, 0x1F, 0xC3, 0x02, 0x8A, |
| 1716 | 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, |
| 1717 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1718 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1719 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1720 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1721 | 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, |
| 1722 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, 0x00, 0x20, |
| 1723 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1724 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, 0x00, 0x20, |
| 1725 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1726 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1727 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1728 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1729 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1730 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1731 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1732 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x37, |
| 1733 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1734 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1735 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1736 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, |
| 1737 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x21, 0x00, 0x02, 0x00, 0x08, |
| 1738 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, |
| 1739 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1740 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, |
| 1741 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1742 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0C, |
| 1743 | 0x00, 0x21, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x21, |
| 1744 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1745 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x21, 0x00, 0x0E, |
| 1746 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1747 | 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, |
| 1748 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, |
| 1749 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1750 | 0x00, 0x0C, 0x00, 0x21, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, |
| 1751 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1752 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x08, 0x00, 0x08, |
| 1753 | 0x00, 0x08, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, |
| 1754 | 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, |
| 1755 | 0x00, 0x0E, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, |
| 1756 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x02, |
| 1757 | 0x00, 0x02, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x02, 0x00, 0x00, |
| 1758 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, |
| 1759 | 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1760 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, 0x00, 0x08, |
| 1761 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, |
| 1762 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, |
| 1763 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1764 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1765 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, |
| 1766 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1767 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1768 | 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, |
| 1769 | 0x00, 0x08, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1770 | 0x00, 0x02}; |
| 1771 | uchar dest[sizeof(expected)]; |
| 1772 | |
| 1773 | StartBenchmarkTiming(); |
| 1774 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1775 | my_strnxfrm(cs, dest, sizeof(dest), |
| 1776 | reinterpret_cast<const uchar *>(content), len); |
| 1777 | } |
| 1778 | StopBenchmarkTiming(); |
| 1779 | |
| 1780 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 1781 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1782 | } |
| 1783 | BENCHMARK(BM_Japanese_AS_CS_KS) |
| 1784 | |
| 1785 | TEST(StrXfrmTest, ChineseUTF8MB4) { |
| 1786 | CHARSET_INFO *cs = init_collation("utf8mb4_zh_0900_as_cs"); |
| 1787 | |
| 1788 | const char *src = |
| 1789 | "\xE9\x98\xBF\xE5\x92\x97" // The first and last Han character in zh.xml |
| 1790 | "\xF0\xAC\xBA\xA1" // The last Han character |
| 1791 | "\xC4\x81\x61\x62\xC5\xAB\x75\x55\xC7\x96\x5A" // Some latin characters |
| 1792 | // are used as Bopomofo. |
| 1793 | "\xF0\x94\x99\x86" // The last character that has explicit weight |
| 1794 | // in the DUCET. |
| 1795 | |
| 1796 | /* Non-Han characters that have implicit weight. */ |
| 1797 | "\xF0\x97\x86\xA0\xF0\xAC\xBA\xA2\xF0\xAE\xAF\xA0\xF0\xB3\x8C\xB3"; |
| 1798 | |
| 1799 | static const unsigned char full_answer_with_pad[116] = { |
| 1800 | // level 1 |
| 1801 | 0x1C, 0x47, 0xBD, 0xBE, // The first and last Han character in zh.xml |
| 1802 | 0xBD, 0xC3, 0xCE, 0xA1, // The last Han character |
| 1803 | /* Latin characters. Some are used as Bopomofo. */ |
| 1804 | 0xBD, 0xC4, 0xBD, 0xC4, 0xBD, 0xDD, 0xC0, 0x32, 0xC0, 0x32, 0xC0, 0x32, |
| 1805 | 0xC0, 0x32, 0xC0, 0x9E, |
| 1806 | |
| 1807 | 0xF6, 0x20, // The last character that has explicit weight in the DUCET. |
| 1808 | /* Non-Han characters that have implicit weight. */ |
| 1809 | 0xF6, 0x21, 0x81, 0xA0, 0xF6, 0x27, 0xCE, 0xA2, 0xF6, 0x27, 0xEB, 0xE0, |
| 1810 | 0xF6, 0x28, 0xB3, 0x33, |
| 1811 | |
| 1812 | // level separator. |
| 1813 | 0x00, 0x00, |
| 1814 | |
| 1815 | // level 2 |
| 1816 | 0x00, 0x20, 0x00, 0x20, // The first and last Han character in zh.xml |
| 1817 | 0x00, 0x20, // The last Han character |
| 1818 | |
| 1819 | /* Latin characters. Some are used as Bopomofo. */ |
| 1820 | 0x00, 0x1F, 0x01, 0x16, 0x00, 0x20, 0x00, 0x20, 0x00, 0x1F, 0x01, 0x16, |
| 1821 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x01, 0x16, 0x00, 0x20, |
| 1822 | |
| 1823 | 0x00, 0x20, // The last character that has explicit weight in the DUCET. |
| 1824 | /* Non-Han characters that have implicit weight. */ |
| 1825 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1826 | // level separator. |
| 1827 | 0x00, 0x00, |
| 1828 | |
| 1829 | // level 3 |
| 1830 | 0x00, 0x02, 0x00, 0x02, // The first and last Han character in zh.xml |
| 1831 | 0x00, 0x02, // The last Han character |
| 1832 | /* Latin characters. Some are used as Bopomofo. */ |
| 1833 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x08, |
| 1834 | 0x00, 0x08, 0x00, 0x08, |
| 1835 | |
| 1836 | 0x00, 0x02, // The last character that has explicit weight in the DUCET. |
| 1837 | /* Non-Han characters that have implicit weight. */ |
| 1838 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02}; |
| 1839 | |
| 1840 | unsigned char buf[sizeof(full_answer_with_pad)]; |
| 1841 | for (size_t maxlen = 0; maxlen < sizeof(buf); maxlen += 2) { |
| 1842 | memset(buf, 0xff, sizeof(buf)); |
| 1843 | my_strnxfrm(cs, buf, maxlen, pointer_cast<const uchar *>(src), strlen(src)); |
| 1844 | expect_arrays_equal(full_answer_with_pad, buf, maxlen); |
| 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | static void BM_Chinese_AS_CS(size_t num_iterations) { |
| 1849 | StopBenchmarkTiming(); |
| 1850 | |
| 1851 | CHARSET_INFO *cs = init_collation("utf8mb4_zh_0900_as_cs"); |
| 1852 | const char *content = |
| 1853 | "春江潮水连海平,海上明月共潮生。" |
| 1854 | "滟滟随波千万里,何处春江无月明!" |
| 1855 | "江流宛转绕芳甸,月照花林皆似霰;" |
| 1856 | "空里流霜不觉飞,汀上白沙看不见。" |
| 1857 | "江天一色无纤尘,皎皎空中孤月轮。" |
| 1858 | "江畔何人初见月?江月何年初照人?" |
| 1859 | "人生代代无穷已,江月年年只相似。" |
| 1860 | "不知江月待何人,但见长江送流水。" |
| 1861 | "白云一片去悠悠,青枫浦上不胜愁。" |
| 1862 | "谁家今夜扁舟子?何处相思明月楼?"; |
| 1863 | const int len = strlen(content); |
| 1864 | |
| 1865 | // Just recorded from a trial run on the string above. |
| 1866 | static constexpr uchar expected[] = { |
| 1867 | 0x2C, 0xD0, 0x4F, 0xF1, 0x28, 0x08, 0x87, 0xE8, 0x60, 0x4C, 0x42, 0xEF, |
| 1868 | 0x75, 0x93, 0x02, 0x22, 0x42, 0xEF, 0x83, 0x8A, 0x6C, 0x4F, 0xAF, 0x96, |
| 1869 | 0x3F, 0x58, 0x28, 0x08, 0x84, 0xCF, 0x02, 0x8A, 0xA3, 0xA4, 0xA3, 0xA4, |
| 1870 | 0x8A, 0x5F, 0x23, 0x71, 0x78, 0xA8, 0x93, 0x1A, 0x5E, 0xD9, 0x02, 0x22, |
| 1871 | 0x44, 0xAC, 0x2B, 0xD5, 0x2C, 0xD0, 0x4F, 0xF1, 0x96, 0x31, 0xAF, 0x96, |
| 1872 | 0x6C, 0x4F, 0x02, 0x60, 0x4F, 0xF1, 0x63, 0x7B, 0x92, 0xDD, 0xBA, 0x2E, |
| 1873 | 0x7F, 0x07, 0x39, 0x15, 0x32, 0xB2, 0x02, 0x22, 0xAF, 0x96, 0xB4, 0x41, |
| 1874 | 0x47, 0xD7, 0x62, 0x27, 0x51, 0x4C, 0x85, 0xE9, 0x81, 0x86, 0x02, 0x34, |
| 1875 | 0x59, 0x09, 0x5E, 0xD9, 0x63, 0x7B, 0x87, 0xBA, 0x24, 0x78, 0x56, 0x5A, |
| 1876 | 0x39, 0x48, 0x02, 0x22, 0x8F, 0x74, 0x83, 0x8A, 0x1E, 0x4D, 0x82, 0x46, |
| 1877 | 0x57, 0xD9, 0x24, 0x78, 0x4F, 0x79, 0x02, 0x8A, 0x4F, 0xF1, 0x8E, 0x8A, |
| 1878 | 0xA6, 0x3E, 0x81, 0xEE, 0x96, 0x31, 0x99, 0x9E, 0x28, 0x97, 0x02, 0x22, |
| 1879 | 0x50, 0xC2, 0x50, 0xC2, 0x59, 0x09, 0xB8, 0x20, 0x3F, 0xCC, 0xAF, 0x96, |
| 1880 | 0x66, 0xC9, 0x02, 0x8A, 0x4F, 0xF1, 0x72, 0xB6, 0x44, 0xAC, 0x7F, 0x11, |
| 1881 | 0x2B, 0x7B, 0x4F, 0x79, 0xAF, 0x96, 0x02, 0x66, 0x4F, 0xF1, 0xAF, 0x96, |
| 1882 | 0x44, 0xAC, 0x6F, 0xD5, 0x2B, 0x7B, 0xB4, 0x41, 0x7F, 0x11, 0x02, 0x66, |
| 1883 | 0x7F, 0x11, 0x84, 0xCF, 0x2F, 0xE2, 0x2F, 0xE2, 0x96, 0x31, 0x7B, 0xE1, |
| 1884 | 0xA7, 0x41, 0x02, 0x22, 0x4F, 0xF1, 0xAF, 0x96, 0x6F, 0xD5, 0x6F, 0xD5, |
| 1885 | 0xB6, 0xC3, 0x9B, 0x15, 0x85, 0xE9, 0x02, 0x8A, 0x24, 0x78, 0xB6, 0x2E, |
| 1886 | 0x4F, 0xF1, 0xAF, 0x96, 0x2F, 0xF4, 0x44, 0xAC, 0x7F, 0x11, 0x02, 0x22, |
| 1887 | 0x30, 0x86, 0x4F, 0x79, 0xB3, 0xDD, 0x4F, 0xF1, 0x89, 0x2A, 0x63, 0x7B, |
| 1888 | 0x87, 0xE8, 0x02, 0x8A, 0x1E, 0x4D, 0xB0, 0x1B, 0xA6, 0x3E, 0x75, 0x00, |
| 1889 | 0x7D, 0x93, 0xAB, 0xAF, 0xAB, 0xAF, 0x02, 0x22, 0x7B, 0x7D, 0x3A, 0x63, |
| 1890 | 0x76, 0xA2, 0x83, 0x8A, 0x24, 0x78, 0x85, 0x16, 0x2B, 0x2D, 0x02, 0x8A, |
| 1891 | 0x84, 0x30, 0x4D, 0xF3, 0x52, 0x63, 0xA5, 0xC7, 0x21, 0xE0, 0xB8, 0x87, |
| 1892 | 0xBC, 0x16, 0x02, 0x66, 0x44, 0xAC, 0x2B, 0xD5, 0x9B, 0x15, 0x88, 0x52, |
| 1893 | 0x6C, 0x4F, 0xAF, 0x96, 0x64, 0xA1, 0x02, 0x66, 0x00, 0x00, 0x00, 0x20, |
| 1894 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1895 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1896 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1897 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1898 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1899 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1900 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1901 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1902 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1903 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1904 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1905 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1906 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1907 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1908 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1909 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1910 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1911 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1912 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1913 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1914 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1915 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1916 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1917 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1918 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1919 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, |
| 1920 | 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, |
| 1921 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, |
| 1922 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1923 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1924 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, |
| 1925 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, |
| 1926 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1927 | 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1928 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, |
| 1929 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, |
| 1930 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1931 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1932 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, |
| 1933 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1934 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1935 | 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1936 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, |
| 1937 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, |
| 1938 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1939 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1940 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, |
| 1941 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1942 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1943 | 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1944 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1945 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, |
| 1946 | 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, |
| 1947 | 0x00, 0x02, 0x00, 0x03}; |
| 1948 | uchar dest[sizeof(expected)]; |
| 1949 | |
| 1950 | StartBenchmarkTiming(); |
| 1951 | for (size_t i = 0; i < num_iterations; ++i) { |
| 1952 | my_strnxfrm(cs, dest, sizeof(dest), |
| 1953 | reinterpret_cast<const uchar *>(content), len); |
| 1954 | } |
| 1955 | StopBenchmarkTiming(); |
| 1956 | |
| 1957 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 1958 | SetBytesProcessed(num_iterations * strlen(content)); |
| 1959 | } |
| 1960 | BENCHMARK(BM_Chinese_AS_CS) |
| 1961 | |
| 1962 | static void BM_UTF8MB4_bin(size_t num_iterations) { |
| 1963 | StopBenchmarkTiming(); |
| 1964 | |
| 1965 | CHARSET_INFO *cs = init_collation("utf8mb4_bin"); |
| 1966 | const char *content = |
| 1967 | "Premature optimization is the root of all evil. " |
| 1968 | "Våre norske tegn bør æres. 日本語が少しわかります。 " |
| 1969 | "✌️🐶👩🏽"; |
| 1970 | const int len = strlen(content); |
| 1971 | |
| 1972 | // Just recorded from a trial run on the string above. |
| 1973 | static constexpr uchar expected[] = { |
| 1974 | 0x00, 0x00, 0x50, 0x00, 0x00, 0x72, 0x00, 0x00, 0x65, 0x00, 0x00, 0x6D, |
| 1975 | 0x00, 0x00, 0x61, 0x00, 0x00, 0x74, 0x00, 0x00, 0x75, 0x00, 0x00, 0x72, |
| 1976 | 0x00, 0x00, 0x65, 0x00, 0x00, 0x20, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x70, |
| 1977 | 0x00, 0x00, 0x74, 0x00, 0x00, 0x69, 0x00, 0x00, 0x6D, 0x00, 0x00, 0x69, |
| 1978 | 0x00, 0x00, 0x7A, 0x00, 0x00, 0x61, 0x00, 0x00, 0x74, 0x00, 0x00, 0x69, |
| 1979 | 0x00, 0x00, 0x6F, 0x00, 0x00, 0x6E, 0x00, 0x00, 0x20, 0x00, 0x00, 0x69, |
| 1980 | 0x00, 0x00, 0x73, 0x00, 0x00, 0x20, 0x00, 0x00, 0x74, 0x00, 0x00, 0x68, |
| 1981 | 0x00, 0x00, 0x65, 0x00, 0x00, 0x20, 0x00, 0x00, 0x72, 0x00, 0x00, 0x6F, |
| 1982 | 0x00, 0x00, 0x6F, 0x00, 0x00, 0x74, 0x00, 0x00, 0x20, 0x00, 0x00, 0x6F, |
| 1983 | 0x00, 0x00, 0x66, 0x00, 0x00, 0x20, 0x00, 0x00, 0x61, 0x00, 0x00, 0x6C, |
| 1984 | 0x00, 0x00, 0x6C, 0x00, 0x00, 0x20, 0x00, 0x00, 0x65, 0x00, 0x00, 0x76, |
| 1985 | 0x00, 0x00, 0x69, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x2E, 0x00, 0x00, 0x20, |
| 1986 | 0x00, 0x00, 0x56, 0x00, 0x00, 0xE5, 0x00, 0x00, 0x72, 0x00, 0x00, 0x65, |
| 1987 | 0x00, 0x00, 0x20, 0x00, 0x00, 0x6E, 0x00, 0x00, 0x6F, 0x00, 0x00, 0x72, |
| 1988 | 0x00, 0x00, 0x73, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x65, 0x00, 0x00, 0x20, |
| 1989 | 0x00, 0x00, 0x74, 0x00, 0x00, 0x65, 0x00, 0x00, 0x67, 0x00, 0x00, 0x6E, |
| 1990 | 0x00, 0x00, 0x20, 0x00, 0x00, 0x62, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x72, |
| 1991 | 0x00, 0x00, 0x20, 0x00, 0x00, 0xE6, 0x00, 0x00, 0x72, 0x00, 0x00, 0x65, |
| 1992 | 0x00, 0x00, 0x73, 0x00, 0x00, 0x2E, 0x00, 0x00, 0x20, 0x00, 0x65, 0xE5, |
| 1993 | 0x00, 0x67, 0x2C, 0x00, 0x8A, 0x9E, 0x00, 0x30, 0x4C, 0x00, 0x5C, 0x11, |
| 1994 | 0x00, 0x30, 0x57, 0x00, 0x30, 0x8F, 0x00, 0x30, 0x4B, 0x00, 0x30, 0x8A, |
| 1995 | 0x00, 0x30, 0x7E, 0x00, 0x30, 0x59, 0x00, 0x30, 0x02, 0x00, 0x00, 0x20, |
| 1996 | 0x00, 0x27, 0x0C, 0x00, 0xFE, 0x0F, 0x01, 0xF4, 0x36, 0x01, 0xF4, 0x69, |
| 1997 | 0x01, 0xF3, 0xFD}; |
| 1998 | uchar dest[sizeof(expected)]; |
| 1999 | |
| 2000 | StartBenchmarkTiming(); |
| 2001 | for (size_t i = 0; i < num_iterations; ++i) { |
| 2002 | my_strnxfrm(cs, dest, sizeof(dest), |
| 2003 | reinterpret_cast<const uchar *>(content), len); |
| 2004 | } |
| 2005 | StopBenchmarkTiming(); |
| 2006 | |
| 2007 | expect_arrays_equal(expected, dest, sizeof(dest)); |
| 2008 | SetBytesProcessed(num_iterations * strlen(content)); |
| 2009 | } |
| 2010 | BENCHMARK(BM_UTF8MB4_bin) |
| 2011 | |
| 2012 | static void BM_UTF8MB4_0900_bin(size_t num_iterations) { |
| 2013 | StopBenchmarkTiming(); |
| 2014 | |
| 2015 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_bin"); |
| 2016 | const char *content = |
| 2017 | "Premature optimization is the root of all evil. " |
| 2018 | "Våre norske tegn bør æres. 日本語が少しわかります。 " |
| 2019 | "✌️🐶👩🏽"; |
| 2020 | const int len = strlen(content); |
| 2021 | |
| 2022 | uchar *dest = new uchar[len]; |
| 2023 | |
| 2024 | StartBenchmarkTiming(); |
| 2025 | for (size_t i = 0; i < num_iterations; ++i) { |
| 2026 | my_strnxfrm(cs, dest, len, reinterpret_cast<const uchar *>(content), len); |
| 2027 | } |
| 2028 | StopBenchmarkTiming(); |
| 2029 | |
| 2030 | /* |
| 2031 | utf8mb4_0900_bin_nopad gives the weight that has same bytes and length as |
| 2032 | source string. |
| 2033 | */ |
| 2034 | expect_arrays_equal((const uchar *)content, dest, len); |
| 2035 | delete[] dest; |
| 2036 | SetBytesProcessed(num_iterations * len); |
| 2037 | } |
| 2038 | BENCHMARK(BM_UTF8MB4_0900_bin) |
| 2039 | |
| 2040 | // The classic MySQL latin1 collation, for reference. |
| 2041 | static void BM_Latin1_CI(size_t num_iterations) { |
| 2042 | StopBenchmarkTiming(); |
| 2043 | |
| 2044 | CHARSET_INFO *cs = init_collation("latin1_swedish_ci"); |
| 2045 | |
| 2046 | const char *content = |
| 2047 | "Alla människor är födda fria och lika i värde " |
| 2048 | "och rättigheter. De är utrustade med förnuft och samvete och bör " |
| 2049 | "handla gentemot varandra i en anda av broderskap."; |
| 2050 | const int len = strlen(content); |
| 2051 | |
| 2052 | /* |
| 2053 | Just recorded from a trial run on the string above. |
| 2054 | The entire last row is padding. |
| 2055 | */ |
| 2056 | static constexpr uchar expected[] = { |
| 2057 | 0x41, 0x4c, 0x4c, 0x41, 0x20, 0x4d, 0x41, 0xa4, 0x4e, 0x4e, 0x49, 0x53, |
| 2058 | 0x4b, 0x4f, 0x52, 0x20, 0x41, 0xa4, 0x52, 0x20, 0x46, 0x41, 0xb6, 0x44, |
| 2059 | 0x44, 0x41, 0x20, 0x46, 0x52, 0x49, 0x41, 0x20, 0x4f, 0x43, 0x48, 0x20, |
| 2060 | 0x4c, 0x49, 0x4b, 0x41, 0x20, 0x49, 0x20, 0x56, 0x41, 0xa4, 0x52, 0x44, |
| 2061 | 0x45, 0x20, 0x4f, 0x43, 0x48, 0x20, 0x52, 0x41, 0xa4, 0x54, 0x54, 0x49, |
| 2062 | 0x47, 0x48, 0x45, 0x54, 0x45, 0x52, 0x2e, 0x20, 0x44, 0x45, 0x20, 0x41, |
| 2063 | 0xa4, 0x52, 0x20, 0x55, 0x54, 0x52, 0x55, 0x53, 0x54, 0x41, 0x44, 0x45, |
| 2064 | 0x20, 0x4d, 0x45, 0x44, 0x20, 0x46, 0x41, 0xb6, 0x52, 0x4e, 0x55, 0x46, |
| 2065 | 0x54, 0x20, 0x4f, 0x43, 0x48, 0x20, 0x53, 0x41, 0x4d, 0x56, 0x45, 0x54, |
| 2066 | 0x45, 0x20, 0x4f, 0x43, 0x48, 0x20, 0x42, 0x41, 0xb6, 0x52, 0x20, 0x48, |
| 2067 | 0x41, 0x4e, 0x44, 0x4c, 0x41, 0x20, 0x47, 0x45, 0x4e, 0x54, 0x45, 0x4d, |
| 2068 | 0x4f, 0x54, 0x20, 0x56, 0x41, 0x52, 0x41, 0x4e, 0x44, 0x52, 0x41, 0x20, |
| 2069 | 0x49, 0x20, 0x45, 0x4e, 0x20, 0x41, 0x4e, 0x44, 0x41, 0x20, 0x41, 0x56, |
| 2070 | 0x20, 0x42, 0x52, 0x4f, 0x44, 0x45, 0x52, 0x53, 0x4b, 0x41, 0x50, 0x2e, |
| 2071 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 2072 | }; |
| 2073 | uchar dest[sizeof(expected)]; |
| 2074 | |
| 2075 | size_t ret = 0; |
| 2076 | StartBenchmarkTiming(); |
| 2077 | for (size_t i = 0; i < num_iterations; ++i) { |
| 2078 | ret = cs->coll->strnxfrm(cs, dest, sizeof(dest), sizeof(dest), |
| 2079 | pointer_cast<const uchar *>(content), len, |
| 2080 | MY_STRXFRM_PAD_TO_MAXLEN); |
| 2081 | } |
| 2082 | StopBenchmarkTiming(); |
| 2083 | |
| 2084 | EXPECT_EQ(sizeof(expected), ret); |
| 2085 | expect_arrays_equal(expected, dest, ret); |
| 2086 | |
| 2087 | SetBytesProcessed(num_iterations * strlen(content)); |
| 2088 | } |
| 2089 | BENCHMARK(BM_Latin1_CI) |
| 2090 | |
| 2091 | // Since the UCA collations are NO PAD, strnncollsp should heed spaces. |
| 2092 | TEST(PadCollationTest, BasicTest) { |
| 2093 | constexpr char foo[] = "foo"; |
| 2094 | constexpr char foosp[] = "foo "; |
| 2095 | constexpr char bar[] = "bar"; |
| 2096 | constexpr char foobar[] = "foobar"; |
| 2097 | |
| 2098 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 2099 | auto my_strnncollsp = cs->coll->strnncollsp; |
| 2100 | |
| 2101 | // "foo" == "foo" |
| 2102 | EXPECT_EQ(my_strnncollsp(cs, pointer_cast<const uchar *>(foo), strlen(foo), |
| 2103 | pointer_cast<const uchar *>(foo), strlen(foo)), |
| 2104 | 0); |
| 2105 | // "foo" < "foo " |
| 2106 | EXPECT_LT(my_strnncollsp(cs, pointer_cast<const uchar *>(foo), strlen(foo), |
| 2107 | pointer_cast<const uchar *>(foosp), strlen(foosp)), |
| 2108 | 0); |
| 2109 | // "foo" > "bar" |
| 2110 | EXPECT_GT(my_strnncollsp(cs, pointer_cast<const uchar *>(foo), strlen(foo), |
| 2111 | pointer_cast<const uchar *>(bar), strlen(bar)), |
| 2112 | 0); |
| 2113 | // "foo" < "foobar". |
| 2114 | EXPECT_LT(my_strnncollsp(cs, pointer_cast<const uchar *>(foo), strlen(foo), |
| 2115 | pointer_cast<const uchar *>(foobar), strlen(foobar)), |
| 2116 | 0); |
| 2117 | |
| 2118 | // Exactly the same tests in reverse. |
| 2119 | |
| 2120 | // "foo " > "foo" |
| 2121 | EXPECT_GT( |
| 2122 | my_strnncollsp(cs, pointer_cast<const uchar *>(foosp), strlen(foosp), |
| 2123 | pointer_cast<const uchar *>(foo), strlen(foo)), |
| 2124 | 0); |
| 2125 | // "bar" < "foo" |
| 2126 | EXPECT_LT(my_strnncollsp(cs, pointer_cast<const uchar *>(bar), strlen(bar), |
| 2127 | pointer_cast<const uchar *>(foo), strlen(foo)), |
| 2128 | 0); |
| 2129 | // "foobar" > "foo". |
| 2130 | EXPECT_GT( |
| 2131 | my_strnncollsp(cs, pointer_cast<const uchar *>(foobar), strlen(foobar), |
| 2132 | pointer_cast<const uchar *>(foo), strlen(foo)), |
| 2133 | 0); |
| 2134 | } |
| 2135 | |
| 2136 | TEST(StrxfrmTest, NoPadCollation) { |
| 2137 | CHARSET_INFO *ai_ci = init_collation("utf8mb4_0900_ai_ci"); |
| 2138 | CHARSET_INFO *as_cs = init_collation("utf8mb4_0900_as_cs"); |
| 2139 | CHARSET_INFO *as_ci = init_collation("utf8mb4_0900_as_ci"); |
| 2140 | |
| 2141 | // Basic sanity checks. |
| 2142 | EXPECT_EQ(compare_through_strxfrm(ai_ci, "abc", "abc"), 0); |
| 2143 | EXPECT_NE(compare_through_strxfrm(as_ci, "abc", "Ǎḅç"), 0); |
| 2144 | EXPECT_NE(compare_through_strxfrm(ai_ci, "abc", "def"), 0); |
| 2145 | EXPECT_NE(compare_through_strxfrm(as_ci, "abc", "def"), 0); |
| 2146 | |
| 2147 | // Spaces from the end should matter, no matter the collation. |
| 2148 | EXPECT_LT(compare_through_strxfrm(ai_ci, "abc", "abc "), 0); |
| 2149 | EXPECT_LT(compare_through_strxfrm(as_ci, "abc", "Ǎḅç "), 0); |
| 2150 | EXPECT_LT(compare_through_strxfrm(as_cs, "abc", "abc "), 0); |
| 2151 | EXPECT_LT(compare_through_strxfrm(as_cs, "abc", "Abc "), 0); |
| 2152 | |
| 2153 | // Same with other types of spaces. |
| 2154 | EXPECT_LT(compare_through_strxfrm(ai_ci, "abc", u8"abc \u00a0"), 0); |
| 2155 | |
| 2156 | // Non-breaking space should compare _equal_ to space in ai_ci and as_ci, |
| 2157 | // but _after_ in as_cs. |
| 2158 | EXPECT_EQ(compare_through_strxfrm(ai_ci, "abc ", u8"abc\u00a0"), 0); |
| 2159 | EXPECT_EQ(compare_through_strxfrm(as_ci, "abc ", u8"abc\u00a0"), 0); |
| 2160 | EXPECT_LT(compare_through_strxfrm(as_cs, "abc ", u8"abc\u00a0"), 0); |
| 2161 | |
| 2162 | // Also in the middle of the string. |
| 2163 | EXPECT_EQ(compare_through_strxfrm(ai_ci, "a c", u8"a\u00a0c"), 0); |
| 2164 | EXPECT_EQ(compare_through_strxfrm(as_ci, "a c", u8"a\u00a0c"), 0); |
| 2165 | EXPECT_LT(compare_through_strxfrm(as_cs, "a c", u8"a\u00a0c"), 0); |
| 2166 | |
| 2167 | // Verify that space in the middle of the string isn't stripped. |
| 2168 | EXPECT_LT(compare_through_strxfrm(ai_ci, "ab c", "abc"), 0); |
| 2169 | EXPECT_LT(compare_through_strxfrm(as_ci, "ab c", "abc"), 0); |
| 2170 | EXPECT_LT(compare_through_strxfrm(as_cs, "ab c", "abc"), 0); |
| 2171 | |
| 2172 | // Whitespace ordering as specified by DUCET. |
| 2173 | EXPECT_GT(compare_through_strxfrm(as_ci, " ", "\t"), 0); |
| 2174 | EXPECT_GT(compare_through_strxfrm(as_cs, " ", "\t"), 0); |
| 2175 | EXPECT_LT(compare_through_strxfrm(as_cs, "", "\t"), 0); |
| 2176 | } |
| 2177 | |
| 2178 | TEST(StrxfrmTest, Contractions) { |
| 2179 | CHARSET_INFO *hu_ai_ci = init_collation("utf8mb4_hu_0900_ai_ci"); |
| 2180 | |
| 2181 | // Basic sanity checks. |
| 2182 | EXPECT_EQ(compare_through_strxfrm(hu_ai_ci, "abc", "abc"), 0); |
| 2183 | EXPECT_NE(compare_through_strxfrm(hu_ai_ci, "abc", "def"), 0); |
| 2184 | EXPECT_EQ(compare_through_strxfrm(hu_ai_ci, "abc", "Abc"), 0); |
| 2185 | |
| 2186 | // "cs" counts as a separate letter, where c < cs < d, so: |
| 2187 | EXPECT_LT(compare_through_strxfrm(hu_ai_ci, "c", "cs"), 0); |
| 2188 | EXPECT_LT(compare_through_strxfrm(hu_ai_ci, "cs", "d"), 0); |
| 2189 | EXPECT_LT(compare_through_strxfrm(hu_ai_ci, "ct", "cst"), 0); |
| 2190 | EXPECT_LT(compare_through_strxfrm(hu_ai_ci, "cst", "dt"), 0); |
| 2191 | |
| 2192 | // Wikipedia gives this as an example. |
| 2193 | EXPECT_LT(compare_through_strxfrm(hu_ai_ci, "cukor", "csak"), 0); |
| 2194 | } |
| 2195 | |
| 2196 | /* |
| 2197 | This test is disabled by default since it needs ~10 seconds to run, |
| 2198 | even in optimized mode. |
| 2199 | */ |
| 2200 | TEST(BitfiddlingTest, DISABLED_FastOutOfRange) { |
| 2201 | unsigned char bytes[4]; |
| 2202 | for (int a = 0; a < 256; ++a) { |
| 2203 | bytes[0] = a; |
| 2204 | for (int b = 0; b < 256; ++b) { |
| 2205 | bytes[1] = b; |
| 2206 | for (int c = 0; c < 256; ++c) { |
| 2207 | bytes[2] = c; |
| 2208 | for (int d = 0; d < 256; ++d) { |
| 2209 | bytes[3] = d; |
| 2210 | bool any_out_of_range_slow = |
| 2211 | (a < 0x20 || a > 0x7e) || (b < 0x20 || b > 0x7e) || |
| 2212 | (c < 0x20 || c > 0x7e) || (d < 0x20 || d > 0x7e); |
| 2213 | |
| 2214 | uint32 four_bytes; |
| 2215 | memcpy(&four_bytes, bytes, sizeof(four_bytes)); |
| 2216 | bool any_out_of_range_fast = |
| 2217 | (((four_bytes + 0x01010101u) & 0x80808080) || |
| 2218 | ((four_bytes - 0x20202020u) & 0x80808080)); |
| 2219 | |
| 2220 | EXPECT_EQ(any_out_of_range_slow, any_out_of_range_fast); |
| 2221 | } |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | /* |
| 2228 | A version of FastOutOfRange that tests the analogous trick for 16-bit |
| 2229 | integers instead (much, much faster). |
| 2230 | */ |
| 2231 | TEST(BitfiddlingTest, FastOutOfRange16) { |
| 2232 | unsigned char bytes[2]; |
| 2233 | for (int a = 0; a < 256; ++a) { |
| 2234 | bytes[0] = a; |
| 2235 | for (int b = 0; b < 256; ++b) { |
| 2236 | bytes[1] = b; |
| 2237 | bool any_out_of_range_slow = |
| 2238 | (a < 0x20 || a > 0x7e) || (b < 0x20 || b > 0x7e); |
| 2239 | |
| 2240 | uint16 two_bytes; |
| 2241 | memcpy(&two_bytes, bytes, sizeof(two_bytes)); |
| 2242 | bool any_out_of_range_fast = |
| 2243 | (((two_bytes + uint16{0x0101}) & uint16{0x8080}) || |
| 2244 | ((two_bytes - uint16{0x2020}) & uint16{0x8080})); |
| 2245 | |
| 2246 | EXPECT_EQ(any_out_of_range_slow, any_out_of_range_fast); |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | uint64 hash(CHARSET_INFO *cs, const char *str) { |
| 2252 | uint64 nr1 = 1, nr2 = 4; |
| 2253 | cs->coll->hash_sort(cs, pointer_cast<const uchar *>(str), strlen(str), &nr1, |
| 2254 | &nr2); |
| 2255 | return nr1; |
| 2256 | } |
| 2257 | |
| 2258 | /* |
| 2259 | NOTE: In this entire test, there's an infinitesimal chance |
| 2260 | that something that we expect doesn't match, still matches |
| 2261 | by pure accident. |
| 2262 | */ |
| 2263 | TEST(PadCollationTest, HashSort) { |
| 2264 | CHARSET_INFO *ai_ci = init_collation("utf8mb4_0900_ai_ci"); |
| 2265 | CHARSET_INFO *as_cs = init_collation("utf8mb4_0900_as_cs"); |
| 2266 | |
| 2267 | // Basic sanity checks. |
| 2268 | EXPECT_EQ(hash(ai_ci, "abc"), hash(ai_ci, "abc")); |
| 2269 | EXPECT_NE(hash(ai_ci, "abc"), hash(ai_ci, "def")); |
| 2270 | |
| 2271 | // Spaces from the end should matter, no matter the collation. |
| 2272 | EXPECT_NE(hash(ai_ci, "abc"), hash(ai_ci, "abc ")); |
| 2273 | EXPECT_NE(hash(as_cs, "abc"), hash(as_cs, "abc ")); |
| 2274 | EXPECT_NE(hash(as_cs, "abc"), hash(as_cs, "Abc ")); |
| 2275 | |
| 2276 | // Same with other types of spaces. |
| 2277 | EXPECT_NE(hash(ai_ci, "abc"), hash(ai_ci, u8"abc \u00a0")); |
| 2278 | |
| 2279 | // Non-breaking space should compare _equal_ to space in ai_ci, |
| 2280 | // but _inequal_ in as_cs. |
| 2281 | EXPECT_EQ(hash(ai_ci, "abc "), hash(ai_ci, u8"abc\u00a0")); |
| 2282 | EXPECT_NE(hash(as_cs, "abc "), hash(as_cs, u8"abc\u00a0")); |
| 2283 | EXPECT_NE(hash(as_cs, "abc"), hash(as_cs, u8"abc\u00a0")); |
| 2284 | |
| 2285 | // Also in the middle of the string. |
| 2286 | EXPECT_EQ(hash(ai_ci, "a c"), hash(ai_ci, u8"a\u00a0c")); |
| 2287 | EXPECT_NE(hash(as_cs, "a c"), hash(as_cs, u8"a\u00a0c")); |
| 2288 | |
| 2289 | // Verify that space in the middle of the string isn't stripped. |
| 2290 | EXPECT_NE(hash(ai_ci, "ab c"), hash(ai_ci, "abc")); |
| 2291 | EXPECT_NE(hash(as_cs, "ab c"), hash(as_cs, "abc")); |
| 2292 | } |
| 2293 | |
| 2294 | TEST(HashTest, NullPointer) { |
| 2295 | CHARSET_INFO *cs = init_collation("utf8mb4_0900_ai_ci"); |
| 2296 | uint64 nr1 = 1, nr2 = 4; |
| 2297 | |
| 2298 | /* |
| 2299 | We should get the same hash from the empty string no matter what |
| 2300 | the pointer is. |
| 2301 | */ |
| 2302 | cs->coll->hash_sort(cs, nullptr, 0, &nr1, &nr2); |
| 2303 | EXPECT_EQ(nr1, hash(cs, "")); |
| 2304 | |
| 2305 | cs->coll->hash_sort(cs, pointer_cast<const uchar *>(" "), 8, &nr1, |
| 2306 | &nr2); |
| 2307 | // Don't care what the values are, just that we don't crash. |
| 2308 | } |
| 2309 | |
| 2310 | namespace { |
| 2311 | |
| 2312 | // Test that strnxfrmlen() holds for all single characters. |
| 2313 | void test_strnxfrmlen(CHARSET_INFO *cs) { |
| 2314 | pair<size_t, my_wc_t> longest{0, 0}; |
| 2315 | |
| 2316 | uchar inbuf[16], outbuf[256]; // Ought to be enough for anyone. |
| 2317 | const size_t max_len = cs->coll->strnxfrmlen(cs, cs->mbmaxlen); |
| 2318 | |
| 2319 | for (my_wc_t ch = 0; ch <= 0x10ffff; ++ch) { |
| 2320 | size_t in_len = cs->cset->wc_mb(cs, ch, inbuf, inbuf + sizeof(inbuf)); |
| 2321 | if (in_len <= 0) { |
| 2322 | continue; // Not representable in this character set. |
| 2323 | } |
| 2324 | size_t out_len = |
| 2325 | cs->coll->strnxfrm(cs, outbuf, sizeof(outbuf), 1, inbuf, in_len, 0); |
| 2326 | EXPECT_LE(out_len, max_len); |
| 2327 | if (out_len > max_len) { |
| 2328 | fprintf(stderr, "U+%04lX needed more room than strnxfrmlen() claimed\n", |
| 2329 | ch); |
| 2330 | fprintf(stderr, "Weight string:"); |
| 2331 | for (size_t i = 0; i < out_len; ++i) { |
| 2332 | fprintf(stderr, " %02x", outbuf[i]); |
| 2333 | } |
| 2334 | fprintf(stderr, "\n\n"); |
| 2335 | } |
| 2336 | |
| 2337 | longest = max(longest, make_pair(out_len, ch)); |
| 2338 | } |
| 2339 | |
| 2340 | fprintf(stderr, |
| 2341 | "Longest character in '%s': U+%04lX, %d bytes (strnxfrm_len=%d)\n", |
| 2342 | cs->m_coll_name, longest.second, static_cast<int>(longest.first), |
| 2343 | static_cast<int>(max_len)); |
| 2344 | } |
| 2345 | |
| 2346 | } // namespace |
| 2347 | |
| 2348 | TEST(StrxfrmLenTest, StrnxfrmLenIsLongEnoughForAllCharacters) { |
| 2349 | // Load one collation to get everything going. |
| 2350 | init_collation("utf8mb4_0900_ai_ci"); |
| 2351 | |
| 2352 | for (CHARSET_INFO *cs : all_charsets) { |
| 2353 | if (cs && (cs->state & MY_CS_AVAILABLE)) { |
| 2354 | SCOPED_TRACE(cs->m_coll_name); |
| 2355 | test_strnxfrmlen(init_collation(cs->m_coll_name)); |
| 2356 | } |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | // Golden hashes for a test string. These may be stored on disk, so we need to |
| 2361 | // make sure that they never change. |
| 2362 | struct GoldenHashResult { |
| 2363 | pair<uint64, uint64> hash_value; |
| 2364 | }; |
| 2365 | |
| 2366 | TEST(StrmxfrmHashTest, HashStability) { |
| 2367 | // Load one collation to get everything going. |
| 2368 | init_collation("utf8mb4_0900_ai_ci"); |
| 2369 | |
| 2370 | // Reference values. Please keep this list sorted. |
| 2371 | unordered_map<string, GoldenHashResult> expected = { |
| 2372 | {"armscii8_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2373 | {"armscii8_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2374 | {"ascii_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2375 | {"ascii_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2376 | {"big5_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2377 | {"big5_chinese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2378 | {"binary", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2379 | {"cp1250_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2380 | {"cp1250_croatian_ci", {{0xe25aa32298f78f4aLL, 0x000002b0LL}}}, |
| 2381 | {"cp1250_czech_cs", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2382 | {"cp1250_general_ci", {{0x81c46f6c6b06f8fcLL, 0x000002b0LL}}}, |
| 2383 | {"cp1250_polish_ci", {{0xe25aa32298f78f4aLL, 0x000002b0LL}}}, |
| 2384 | {"cp1251_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2385 | {"cp1251_bulgarian_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2386 | {"cp1251_general_ci", {{0xce71da5364c300a4LL, 0x000002b0LL}}}, |
| 2387 | {"cp1251_general_cs", {{0xff44ce45c6d3d142LL, 0x000002b0LL}}}, |
| 2388 | {"cp1251_ukrainian_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2389 | {"cp1256_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2390 | {"cp1256_general_ci", {{0x44ed84e7ad4a6c1cLL, 0x000002b0LL}}}, |
| 2391 | {"cp1257_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2392 | {"cp1257_general_ci", {{0x15219f243a38ad58LL, 0x000002b0LL}}}, |
| 2393 | {"cp1257_lithuanian_ci", {{0xaa3ef638e5e056e8LL, 0x000002b0LL}}}, |
| 2394 | {"cp850_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2395 | {"cp850_general_ci", {{0xf32b1cf4087a0b08LL, 0x000002b0LL}}}, |
| 2396 | {"cp852_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2397 | {"cp852_general_ci", {{0x60dce9bffdeccd52LL, 0x000002b0LL}}}, |
| 2398 | {"cp866_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2399 | {"cp866_general_ci", {{0xce71da5364c300a4LL, 0x000002b0LL}}}, |
| 2400 | {"cp932_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2401 | {"cp932_japanese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2402 | {"dec8_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2403 | {"dec8_swedish_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2404 | {"eucjpms_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2405 | {"eucjpms_japanese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2406 | {"euckr_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2407 | {"euckr_korean_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2408 | {"gb18030_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2409 | {"gb18030_chinese_ci", {{0xb7b6676124243e73LL, 0x00000abdLL}}}, |
| 2410 | {"gb18030_unicode_520_ci", {{0x5c1f019a21e3d464LL, 0x0000055fLL}}}, |
| 2411 | {"gb2312_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2412 | {"gb2312_chinese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2413 | {"gbk_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2414 | {"gbk_chinese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2415 | {"geostd8_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2416 | {"geostd8_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2417 | {"greek_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2418 | {"greek_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2419 | {"hebrew_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2420 | {"hebrew_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2421 | {"hp8_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2422 | {"hp8_english_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2423 | {"keybcs2_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2424 | {"keybcs2_general_ci", {{0xd2d54c0201229650LL, 0x000002b0LL}}}, |
| 2425 | {"koi8r_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2426 | {"koi8r_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2427 | {"koi8u_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2428 | {"koi8u_general_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2429 | {"latin1_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2430 | {"latin1_danish_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2431 | {"latin1_general_ci", {{0xd7d424d55cb8f402LL, 0x000002b0LL}}}, |
| 2432 | {"latin1_general_cs", {{0x96b2a3f94ffe41f9LL, 0x000002b0LL}}}, |
| 2433 | {"latin1_german1_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2434 | {"latin1_german2_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2435 | {"latin1_spanish_ci", {{0xd7d424d55cb8f402LL, 0x000002b0LL}}}, |
| 2436 | {"latin1_swedish_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2437 | {"latin2_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2438 | {"latin2_croatian_ci", {{0xe25aa32298f78f4aLL, 0x000002b0LL}}}, |
| 2439 | {"latin2_czech_cs", {{0xba89a4855c3a88b6LL, 0x000002b0LL}}}, |
| 2440 | {"latin2_general_ci", {{0xd9179195a5ddebf8LL, 0x000002b0LL}}}, |
| 2441 | {"latin2_hungarian_ci", {{0xba89a4855c3a88b6LL, 0x000002b0LL}}}, |
| 2442 | {"latin5_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2443 | {"latin5_turkish_ci", {{0x68989a162aab9f1cLL, 0x000002b0LL}}}, |
| 2444 | {"latin7_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2445 | {"latin7_estonian_cs", {{0xa281f3df87b89fe1LL, 0x000002b0LL}}}, |
| 2446 | {"latin7_general_ci", {{0xc6808727382ffb41LL, 0x000002b0LL}}}, |
| 2447 | {"latin7_general_cs", {{0xf70d2b9f0d640804LL, 0x000002b0LL}}}, |
| 2448 | {"macce_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2449 | {"macce_general_ci", {{0xb27ca521eb9b7492LL, 0x000002b0LL}}}, |
| 2450 | {"macroman_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2451 | {"macroman_general_ci", {{0x3254bac0fa3625efLL, 0x000002b0LL}}}, |
| 2452 | {"sjis_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2453 | {"sjis_japanese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2454 | {"swe7_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2455 | {"swe7_swedish_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2456 | {"tis620_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2457 | {"tis620_thai_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2458 | {"ucs2_bin", {{0x1877f0a25b18b4c6LL, 0x0000055fLL}}}, |
| 2459 | {"ucs2_croatian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2460 | {"ucs2_czech_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2461 | {"ucs2_danish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2462 | {"ucs2_esperanto_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2463 | {"ucs2_estonian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2464 | {"ucs2_general_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2465 | {"ucs2_general_mysql500_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2466 | {"ucs2_german2_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2467 | {"ucs2_hungarian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2468 | {"ucs2_icelandic_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2469 | {"ucs2_latvian_ci", {{0x6473871765c3455cLL, 0x0000055fLL}}}, |
| 2470 | {"ucs2_lithuanian_ci", {{0xccb8395ef1969f40LL, 0x00000553LL}}}, |
| 2471 | {"ucs2_persian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2472 | {"ucs2_polish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2473 | {"ucs2_roman_ci", {{0xf40d4b3c957fccdcLL, 0x0000055fLL}}}, |
| 2474 | {"ucs2_romanian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2475 | {"ucs2_sinhala_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2476 | {"ucs2_slovak_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2477 | {"ucs2_slovenian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2478 | {"ucs2_spanish2_ci", {{0x3e79d9277da1beb4LL, 0x00000547LL}}}, |
| 2479 | {"ucs2_spanish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2480 | {"ucs2_swedish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2481 | {"ucs2_turkish_ci", {{0x3fb28acb6e515c9cLL, 0x0000055fLL}}}, |
| 2482 | {"ucs2_unicode_520_ci", {{0x5c1f019a21e3d464LL, 0x0000055fLL}}}, |
| 2483 | {"ucs2_unicode_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2484 | {"ucs2_vietnamese_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2485 | {"ujis_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2486 | {"ujis_japanese_ci", {{0xdae43ea5cabac97cLL, 0x000002b0LL}}}, |
| 2487 | {"utf16_bin", {{0x1877f0a25b18b4c6LL, 0x0000055fLL}}}, |
| 2488 | {"utf16_croatian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2489 | {"utf16_czech_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2490 | {"utf16_danish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2491 | {"utf16_esperanto_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2492 | {"utf16_estonian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2493 | {"utf16_general_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2494 | {"utf16_german2_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2495 | {"utf16_hungarian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2496 | {"utf16_icelandic_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2497 | {"utf16_latvian_ci", {{0x6473871765c3455cLL, 0x0000055fLL}}}, |
| 2498 | {"utf16_lithuanian_ci", {{0xccb8395ef1969f40LL, 0x00000553LL}}}, |
| 2499 | {"utf16_persian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2500 | {"utf16_polish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2501 | {"utf16_roman_ci", {{0xf40d4b3c957fccdcLL, 0x0000055fLL}}}, |
| 2502 | {"utf16_romanian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2503 | {"utf16_sinhala_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2504 | {"utf16_slovak_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2505 | {"utf16_slovenian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2506 | {"utf16_spanish2_ci", {{0x3e79d9277da1beb4LL, 0x00000547LL}}}, |
| 2507 | {"utf16_spanish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2508 | {"utf16_swedish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2509 | {"utf16_turkish_ci", {{0x3fb28acb6e515c9cLL, 0x0000055fLL}}}, |
| 2510 | {"utf16_unicode_520_ci", {{0x5c1f019a21e3d464LL, 0x0000055fLL}}}, |
| 2511 | {"utf16_unicode_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2512 | {"utf16_vietnamese_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2513 | {"utf16le_bin", {{0x3da26ce08ecbfaf9LL, 0x0000055fLL}}}, |
| 2514 | {"utf16le_general_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2515 | {"utf32_bin", {{0x353330032692faLL, 0x00000abdLL}}}, |
| 2516 | {"utf32_croatian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2517 | {"utf32_czech_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2518 | {"utf32_danish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2519 | {"utf32_esperanto_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2520 | {"utf32_estonian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2521 | {"utf32_general_ci", {{0x353330032692faLL, 0x00000abdLL}}}, |
| 2522 | {"utf32_german2_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2523 | {"utf32_hungarian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2524 | {"utf32_icelandic_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2525 | {"utf32_latvian_ci", {{0x6473871765c3455cLL, 0x0000055fLL}}}, |
| 2526 | {"utf32_lithuanian_ci", {{0xccb8395ef1969f40LL, 0x00000553LL}}}, |
| 2527 | {"utf32_persian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2528 | {"utf32_polish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2529 | {"utf32_roman_ci", {{0xf40d4b3c957fccdcLL, 0x0000055fLL}}}, |
| 2530 | {"utf32_romanian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2531 | {"utf32_sinhala_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2532 | {"utf32_slovak_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2533 | {"utf32_slovenian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2534 | {"utf32_spanish2_ci", {{0x3e79d9277da1beb4LL, 0x00000547LL}}}, |
| 2535 | {"utf32_spanish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2536 | {"utf32_swedish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2537 | {"utf32_turkish_ci", {{0x3fb28acb6e515c9cLL, 0x0000055fLL}}}, |
| 2538 | {"utf32_unicode_520_ci", {{0x5c1f019a21e3d464LL, 0x0000055fLL}}}, |
| 2539 | {"utf32_unicode_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2540 | {"utf32_vietnamese_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2541 | {"utf8mb3_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2542 | {"utf8mb3_croatian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2543 | {"utf8mb3_czech_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2544 | {"utf8mb3_danish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2545 | {"utf8mb3_esperanto_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2546 | {"utf8mb3_estonian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2547 | {"utf8mb3_general_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2548 | {"utf8mb3_general_mysql500_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2549 | {"utf8mb3_german2_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2550 | {"utf8mb3_hungarian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2551 | {"utf8mb3_icelandic_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2552 | {"utf8mb3_latvian_ci", {{0x6473871765c3455cLL, 0x0000055fLL}}}, |
| 2553 | {"utf8mb3_lithuanian_ci", {{0xccb8395ef1969f40LL, 0x00000553LL}}}, |
| 2554 | {"utf8mb3_persian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2555 | {"utf8mb3_polish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2556 | {"utf8mb3_roman_ci", {{0xf40d4b3c957fccdcLL, 0x0000055fLL}}}, |
| 2557 | {"utf8mb3_romanian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2558 | {"utf8mb3_sinhala_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2559 | {"utf8mb3_slovak_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2560 | {"utf8mb3_slovenian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2561 | {"utf8mb3_spanish2_ci", {{0x3e79d9277da1beb4LL, 0x00000547LL}}}, |
| 2562 | {"utf8mb3_spanish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2563 | {"utf8mb3_swedish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2564 | {"utf8mb3_tolower_ci", {{0x8eab9a2c403c8eb9LL, 0x0000055fLL}}}, |
| 2565 | {"utf8mb3_turkish_ci", {{0x3fb28acb6e515c9cLL, 0x0000055fLL}}}, |
| 2566 | {"utf8mb3_unicode_520_ci", {{0x5c1f019a21e3d464LL, 0x0000055fLL}}}, |
| 2567 | {"utf8mb3_unicode_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2568 | {"utf8mb3_vietnamese_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2569 | {"utf8mb4_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2570 | {"utf8mb4_0900_as_ci", {{0xfc978781d49d0d9bLL, 0x00000001LL}}}, |
| 2571 | {"utf8mb4_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2572 | {"utf8mb4_0900_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2573 | {"utf8mb4_bin", {{0xb6240d9a0a0f7efcLL, 0x000002b0LL}}}, |
| 2574 | {"utf8mb4_bg_0900_ai_ci", {{0xb55bc2bf5ab2bf53LL, 0x00000001LL}}}, |
| 2575 | {"utf8mb4_bg_0900_as_cs", {{0x36f5a31292841899LL, 0x00000001LL}}}, |
| 2576 | {"utf8mb4_bs_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2577 | {"utf8mb4_bs_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2578 | {"utf8mb4_croatian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2579 | {"utf8mb4_cs_0900_ai_ci", {{0x36582be4fafa0bbbLL, 0x00000001LL}}}, |
| 2580 | {"utf8mb4_cs_0900_as_cs", {{0xac403419684d8c71LL, 0x00000001LL}}}, |
| 2581 | {"utf8mb4_czech_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2582 | {"utf8mb4_da_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2583 | {"utf8mb4_da_0900_as_cs", {{0xbd24fdcb7b0cf519LL, 0x00000001LL}}}, |
| 2584 | {"utf8mb4_danish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2585 | {"utf8mb4_de_pb_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2586 | {"utf8mb4_de_pb_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2587 | {"utf8mb4_eo_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2588 | {"utf8mb4_eo_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2589 | {"utf8mb4_es_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2590 | {"utf8mb4_es_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2591 | {"utf8mb4_es_trad_0900_ai_ci", {{0x555a77b8a263f17fLL, 0x00000001LL}}}, |
| 2592 | {"utf8mb4_es_trad_0900_as_cs", {{0xae993a138c5c030dLL, 0x00000001LL}}}, |
| 2593 | {"utf8mb4_esperanto_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2594 | {"utf8mb4_estonian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2595 | {"utf8mb4_et_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2596 | {"utf8mb4_et_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2597 | {"utf8mb4_general_ci", {{0xfb66c3f2301bd579LL, 0x0000055fLL}}}, |
| 2598 | {"utf8mb4_german2_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2599 | {"utf8mb4_gl_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2600 | {"utf8mb4_gl_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2601 | {"utf8mb4_hr_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2602 | {"utf8mb4_hr_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2603 | {"utf8mb4_hu_0900_ai_ci", {{0x3162e9e9cebb9148LL, 0x00000001LL}}}, |
| 2604 | {"utf8mb4_hu_0900_as_cs", {{0x88842661c548eec1LL, 0x00000001LL}}}, |
| 2605 | {"utf8mb4_hungarian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2606 | {"utf8mb4_icelandic_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2607 | {"utf8mb4_is_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2608 | {"utf8mb4_is_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2609 | {"utf8mb4_ja_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2610 | {"utf8mb4_ja_0900_as_cs_ks", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2611 | {"utf8mb4_la_0900_ai_ci", {{0x2928cd07bca9a85dLL, 0x00000001LL}}}, |
| 2612 | {"utf8mb4_la_0900_as_cs", {{0x29a7f3eb43a9819LL, 0x00000001LL}}}, |
| 2613 | {"utf8mb4_latvian_ci", {{0x6473871765c3455cLL, 0x0000055fLL}}}, |
| 2614 | {"utf8mb4_lithuanian_ci", {{0xccb8395ef1969f40LL, 0x00000553LL}}}, |
| 2615 | {"utf8mb4_lt_0900_ai_ci", {{0xcd5ce469f67f6792LL, 0x00000001LL}}}, |
| 2616 | {"utf8mb4_lt_0900_as_cs", {{0xe2e6dc41a4d6b3c1LL, 0x00000001LL}}}, |
| 2617 | {"utf8mb4_lv_0900_ai_ci", {{0xcd5ce469f67f6792LL, 0x00000001LL}}}, |
| 2618 | {"utf8mb4_lv_0900_as_cs", {{0xfe377cec9551f0f4LL, 0x00000001LL}}}, |
| 2619 | {"utf8mb4_mn_cyrl_0900_ai_ci", {{0xb55bc2bf5ab2bf53LL, 0x00000001LL}}}, |
| 2620 | {"utf8mb4_mn_cyrl_0900_as_cs", {{0x36f5a31292841899LL, 0x00000001LL}}}, |
| 2621 | {"utf8mb4_nb_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2622 | {"utf8mb4_nb_0900_as_cs", {{0xCFB3E3073C9F5A19LL, 0x00000001LL}}}, |
| 2623 | {"utf8mb4_nn_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2624 | {"utf8mb4_nn_0900_as_cs", {{0xCFB3E3073C9F5A19LL, 0x00000001LL}}}, |
| 2625 | {"utf8mb4_persian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2626 | {"utf8mb4_pl_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2627 | {"utf8mb4_pl_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2628 | {"utf8mb4_polish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2629 | {"utf8mb4_ro_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2630 | {"utf8mb4_ro_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2631 | {"utf8mb4_roman_ci", {{0xf40d4b3c957fccdcLL, 0x0000055fLL}}}, |
| 2632 | {"utf8mb4_romanian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2633 | {"utf8mb4_ru_0900_ai_ci", {{0xb55bc2bf5ab2bf53LL, 0x00000001LL}}}, |
| 2634 | {"utf8mb4_ru_0900_as_cs", {{0x36f5a31292841899LL, 0x00000001LL}}}, |
| 2635 | {"utf8mb4_sinhala_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2636 | {"utf8mb4_sk_0900_ai_ci", {{0x36582be4fafa0bbbLL, 0x00000001LL}}}, |
| 2637 | {"utf8mb4_sk_0900_as_cs", {{0xac403419684d8c71LL, 0x00000001LL}}}, |
| 2638 | {"utf8mb4_sl_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2639 | {"utf8mb4_sl_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2640 | {"utf8mb4_slovak_ci", {{0x1dc65c2738ed47c0LL, 0x00000553LL}}}, |
| 2641 | {"utf8mb4_slovenian_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2642 | {"utf8mb4_spanish2_ci", {{0x3e79d9277da1beb4LL, 0x00000547LL}}}, |
| 2643 | {"utf8mb4_spanish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2644 | {"utf8mb4_sr_latn_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2645 | {"utf8mb4_sr_latn_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2646 | {"utf8mb4_sv_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2647 | {"utf8mb4_sv_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2648 | {"utf8mb4_swedish_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2649 | {"utf8mb4_tr_0900_ai_ci", {{0x7ea67be76364740fLL, 0x00000001LL}}}, |
| 2650 | {"utf8mb4_tr_0900_as_cs", {{0xfa4556e24336675eLL, 0x00000001LL}}}, |
| 2651 | {"utf8mb4_turkish_ci", {{0x3fb28acb6e515c9cLL, 0x0000055fLL}}}, |
| 2652 | {"utf8mb4_unicode_520_ci", {{0x5c1f019a21e3d464LL, 0x0000055fLL}}}, |
| 2653 | {"utf8mb4_unicode_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2654 | {"utf8mb4_vi_0900_ai_ci", {{0x3329a425d0f7f8d3LL, 0x00000001LL}}}, |
| 2655 | {"utf8mb4_vi_0900_as_cs", {{0xcfb3e3073c9f5a19LL, 0x00000001LL}}}, |
| 2656 | {"utf8mb4_vietnamese_ci", {{0x3acdfaa93364f55cLL, 0x0000055fLL}}}, |
| 2657 | {"utf8mb4_zh_0900_as_cs", {{0x23c370d9ac589d1fLL, 0x00000001LL}}}, |
| 2658 | }; |
| 2659 | |
| 2660 | string test_str = |
| 2661 | "This is a fairly long string. It does not contain any special " |
| 2662 | "characters since they are probably not universally supported across all " |
| 2663 | "character sets, but should at least be enough to make the nr1 value go " |
| 2664 | "up past the 32-bit mark."; |
| 2665 | |
| 2666 | for (CHARSET_INFO *cs : all_charsets) { |
| 2667 | if (cs && (cs->state & MY_CS_AVAILABLE)) { |
| 2668 | init_collation(cs->m_coll_name); |
| 2669 | |
| 2670 | char buf[4096]; |
| 2671 | uint errors; |
| 2672 | size_t len = |
| 2673 | my_convert(buf, sizeof(buf), cs, test_str.data(), test_str.size(), |
| 2674 | &my_charset_utf8mb4_0900_ai_ci, &errors); |
| 2675 | ASSERT_EQ(0, errors); |
| 2676 | |
| 2677 | uint64 nr1 = 4, nr2 = 1; |
| 2678 | cs->coll->hash_sort(cs, pointer_cast<const uchar *>(buf), len, &nr1, |
| 2679 | &nr2); |
| 2680 | |
| 2681 | // Change this from false to true to output source code you can paste |
| 2682 | // into “expected” above. |
| 2683 | if (false) { |
| 2684 | printf(" {\"%s\", {{0x%016" PRIx64 "LL, 0x%" PRIx64 "LL}}},\n", |
| 2685 | cs->m_coll_name, nr1, nr2); |
| 2686 | continue; |
| 2687 | } |
| 2688 | |
| 2689 | ASSERT_EQ(1, expected.count(cs->m_coll_name)) |
| 2690 | << "Character set " << cs->m_coll_name |
| 2691 | << " is missing in the database"; |
| 2692 | SCOPED_TRACE(cs->m_coll_name); |
| 2693 | |
| 2694 | EXPECT_EQ(expected[cs->m_coll_name].hash_value.first, nr1); |
| 2695 | EXPECT_EQ(expected[cs->m_coll_name].hash_value.second, nr2); |
| 2696 | } |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | } // namespace strnxfrm_unittest |