diff options
| author | 2021-04-08 18:38:39 +0100 | |
|---|---|---|
| committer | 2021-04-08 18:48:52 +0100 | |
| commit | a6f81edcdb411f5c814ed90e807da0e14a602952 (patch) | |
| tree | fffc6bb6f8b7df6149affec70d8d19b66c3ded58 /src/hashcomp.cpp | |
| parent | Default to rehashing TLS certificates on rehash. (diff) | |
Take a string_view in irc::equals.
Diffstat (limited to 'src/hashcomp.cpp')
| -rw-r--r-- | src/hashcomp.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 37158bb06..ad519540c 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -87,14 +87,20 @@ unsigned const char ascii_case_insensitive_map[256] = { 250, 251, 252, 253, 254, 255, // 250-255 }; -bool irc::equals(const std::string& s1, const std::string& s2) +bool irc::equals(const std::string_view& s1, const std::string_view& s2) { - const unsigned char* n1 = reinterpret_cast<const unsigned char*>(s1.c_str()); - const unsigned char* n2 = reinterpret_cast<const unsigned char*>(s2.c_str()); - for (; *n1 && *n2; n1++, n2++) - if (national_case_insensitive_map[*n1] != national_case_insensitive_map[*n2]) + if (s1.size() != s2.size()) + return false; + + for (size_t idx = 0; idx < s1.length(); ++idx) + { + const unsigned char c1 = s1[idx]; + const unsigned char c2 = s2[idx]; + if (national_case_insensitive_map[c1] != national_case_insensitive_map[c2]) return false; - return (national_case_insensitive_map[*n1] == national_case_insensitive_map[*n2]); + } + + return true; } size_t irc::find(const std::string& haystack, const std::string& needle) |
