19using word_t = std::make_unsigned_t<Tagged_t>;
26template <
class CaseMapping>
27void CheckFastAsciiConvert(
char* dst,
const char* src, uint32_t length) {
28 constexpr bool is_to_lower = CaseMapping::kIsToLower;
29 constexpr char lo = is_to_lower ?
'A' :
'a';
30 constexpr char hi = is_to_lower ?
'Z' :
'z';
31 constexpr int diff = is_to_lower ? (
'a' -
'A') : (
'A' -
'a');
33 if (
lo <= src[
i] && src[
i] <=
hi) {
49template <
char low,
char high>
62template <
class CaseMapping>
64 const char* saved_src = src;
70 constexpr bool is_lower = CaseMapping::kIsToLower;
71 constexpr char lo = is_lower ?
'A' - 1 :
'a' - 1;
72 constexpr char hi = is_lower ?
'Z' + 1 :
'z' + 1;
73 const char*
const limit = src +
length;
79 while (src <= limit -
sizeof(
word_t)) {
81 if ((w &
kAsciiMask) != 0)
return static_cast<int>(src - saved_src);
83 return static_cast<int>(src - saved_src);
90 for (; src < limit; ++src) {
93 return static_cast<int>(src - saved_src);
100 const char* src, uint32_t length);
102 const char* src, uint32_t length);
104template <
class CaseMapping>
107 char* saved_dst = dst;
109 const char* saved_src = src;
115 constexpr bool is_lower = CaseMapping::kIsToLower;
116 constexpr char lo = is_lower ?
'A' - 1 :
'a' - 1;
117 constexpr char hi = is_lower ?
'Z' + 1 :
'z' + 1;
118 const char*
const limit = src +
length;
127 while (src <= limit -
sizeof(
word_t)) {
129 if ((w &
kAsciiMask) != 0)
return static_cast<int>(src - saved_src);
131 *
reinterpret_cast<word_t*
>(dst) = w;
137 while (src <= limit -
sizeof(
word_t)) {
139 if ((w &
kAsciiMask) != 0)
return static_cast<int>(src - saved_src);
144 *
reinterpret_cast<word_t*
>(dst) = w ^ (
m >> 2);
151 while (src < limit) {
153 if ((c &
kAsciiMask) != 0)
return static_cast<int>(src - saved_src);
154 if (
lo < c && c <
hi) {
163 CheckFastAsciiConvert<CaseMapping>(saved_dst, saved_src, length);
template uint32_t FastAsciiConvert< unibrow::ToLowercase >(char *dst, const char *src, uint32_t length)
constexpr word_t kAsciiMask
template uint32_t FastAsciiCasePrefixLength< unibrow::ToUppercase >(const char *src, uint32_t length)
template uint32_t FastAsciiConvert< unibrow::ToUppercase >(char *dst, const char *src, uint32_t length)
uint32_t FastAsciiConvert(char *dst, const char *src, uint32_t length)
std::make_unsigned_t< Tagged_t > word_t
constexpr word_t kOneInEveryByte
uint32_t FastAsciiCasePrefixLength(const char *src, uint32_t length)
static word_t AsciiRangeMask(word_t w)
template uint32_t FastAsciiCasePrefixLength< unibrow::ToLowercase >(const char *src, uint32_t length)
constexpr word_t kWordTAllBitsSet
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
constexpr bool IsAligned(T value, U alignment)