yangsiyu1 commented on code in PR #50: URL: https://github.com/apache/doris-thirdparty/pull/50#discussion_r1163525833
########## src/core/CLucene/util/stringUtil.h: ########## @@ -24,4 +29,52 @@ T *strDuplicate(const T *str); template<typename T> size_t lenOfString(const T *str); + +template <char not_case_lower_bound, char not_case_upper_bound> +class LowerUpperImpl { +public: + static void transfer(const uint8_t* src, const uint8_t* src_end, uint8_t* dst) { + const auto flip_case_mask = 'A' ^ 'a'; + +#if defined(__SSE2__) || defined(__aarch64__) + const auto bytes_sse = sizeof(__m128i); + const auto src_end_sse = src_end - (src_end - src) % bytes_sse; + + const auto v_not_case_lower_bound = _mm_set1_epi8(not_case_lower_bound - 1); + const auto v_not_case_upper_bound = _mm_set1_epi8(not_case_upper_bound + 1); + const auto v_flip_case_mask = _mm_set1_epi8(flip_case_mask); + + for (; src < src_end_sse; src += bytes_sse, dst += bytes_sse) { + const auto chars = _mm_loadu_si128(reinterpret_cast<const __m128i*>(src)); + const auto is_not_case = _mm_and_si128(_mm_cmpgt_epi8(chars, v_not_case_lower_bound), + _mm_cmplt_epi8(chars, v_not_case_upper_bound)); + const auto xor_mask = _mm_and_si128(v_flip_case_mask, is_not_case); + const auto cased_chars = _mm_xor_si128(chars, xor_mask); + _mm_storeu_si128(reinterpret_cast<__m128i*>(dst), cased_chars); + } +#endif + + for (; src < src_end; ++src, ++dst) + if (*src >= not_case_lower_bound && *src <= not_case_upper_bound) + *dst = *src ^ flip_case_mask; + else + *dst = *src; + } +}; + +static void to_lower(const uint8_t* src, int64_t len, uint8_t* dst) { + if (len <= 0) { + return; + } + LowerUpperImpl<'A', 'Z'> lowerUpper; Review Comment: Can directly call static function -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org