Skip to content

Commit

Permalink
Add allocation-free fast path to is_common_tld.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Aug 20, 2022
1 parent fc9e878 commit 0649b7e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions td/telegram/MessageEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,17 @@ static bool is_common_tld(Slice str) {
"zippo", "zm", "zone", "zuerich",
// comment for clang-format to prevent it from placing all strings on separate lines
"zw"});
bool is_lower = true;
for (auto c : str) {
if (static_cast<uint32>(c - 'a') > 'z' - 'a') {
is_lower = false;
break;
}
}
if (is_lower) {
// fast path
return tlds.count(str) > 0;
}
string str_lower = utf8_to_lower(str);
if (str_lower != str && utf8_substr(Slice(str_lower), 1) == utf8_substr(str, 1)) {
return false;
Expand Down

0 comments on commit 0649b7e

Please sign in to comment.