aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp
diff options
context:
space:
mode:
authorvadim-xd <vadim-xd@yandex-team.com>2024-06-09 14:29:51 +0300
committervadim-xd <vadim-xd@yandex-team.com>2024-06-09 14:38:13 +0300
commit22d59c45d8f17195622bd9e5bfa9259c50b1a732 (patch)
tree508002f84f703be6d6f92443827d1a4e255d457f /library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp
parentafd4899380eea1c70e2a68714b5da1c9919ccdbd (diff)
downloadydb-22d59c45d8f17195622bd9e5bfa9259c50b1a732.tar.gz
Add TCaseInsensitiveAsciiString
Followup for rXXXXXX - further optimize ascii-only case insensitive strings 1fca7889a074a191eadce12247bdd6dd18b75ab2
Diffstat (limited to 'library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp')
-rw-r--r--library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp b/library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp
index 78de43343e..8bec888b55 100644
--- a/library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp
+++ b/library/cpp/case_insensitive_string/case_insensitive_char_traits.cpp
@@ -1,14 +1,25 @@
#include "case_insensitive_char_traits.h"
-#include "case_insensitive_string.h"
#include <util/string/escape.h>
+template <typename TImpl>
+const char* ::NPrivate::TCommonCaseInsensitiveCharTraits<TImpl>::find(const char* s, std::size_t n, char a) {
+ const auto ca(TImpl::ToCommonCase(a));
+ while (n-- != 0) {
+ if (TImpl::ToCommonCase(*s) == ca)
+ return s;
+ s++;
+ }
+ return nullptr;
+}
+
int TCaseInsensitiveCharTraits::compare(const char* s1, const char* s2, std::size_t n) {
while (n-- != 0) {
- if (to_upper(*s1) < to_upper(*s2)) {
+ auto c1 = ToCommonCase(*s1), c2 = ToCommonCase(*s2);
+ if (c1 < c2) {
return -1;
}
- if (to_upper(*s1) > to_upper(*s2)) {
+ if (c1 > c2) {
return 1;
}
++s1;
@@ -17,17 +28,5 @@ int TCaseInsensitiveCharTraits::compare(const char* s1, const char* s2, std::siz
return 0;
}
-const char* TCaseInsensitiveCharTraits::find(const char* s, std::size_t n, char a) {
- auto const ua(to_upper(a));
- while (n-- != 0) {
- if (to_upper(*s) == ua)
- return s;
- s++;
- }
- return nullptr;
-}
-
-TCaseInsensitiveString EscapeC(const TCaseInsensitiveString& str) {
- const auto result = EscapeC(str.data(), str.size());
- return {result.data(), result.size()};
-}
+template struct ::NPrivate::TCommonCaseInsensitiveCharTraits<TCaseInsensitiveCharTraits>;
+template struct ::NPrivate::TCommonCaseInsensitiveCharTraits<TCaseInsensitiveAsciiCharTraits>;