From 3c34765595923bba800f5612a48949ae1bfe9c5a Mon Sep 17 00:00:00 2001 From: x7z4w Date: Thu, 21 Aug 2025 13:56:48 +0000 Subject: [PATCH] [core] nits Signed-off-by: x7z4w --- libs/base/string_utils.cpp | 3 +-- libs/base/string_utils.hpp | 14 ++++++++++++++ libs/drape/glyph_manager.cpp | 7 +------ libs/drape/harfbuzz_shaping.cpp | 2 +- libs/search/query_params.cpp | 4 ++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/libs/base/string_utils.cpp b/libs/base/string_utils.cpp index fb8e30c2f..b6369f034 100644 --- a/libs/base/string_utils.cpp +++ b/libs/base/string_utils.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -345,7 +344,7 @@ std::u16string ToUtf16(std::string_view utf8) bool IsASCIIString(std::string_view sv) { - for (auto c : sv) + for (auto const c : sv) if (c & 0x80) return false; return true; diff --git a/libs/base/string_utils.hpp b/libs/base/string_utils.hpp index b9ec4189f..6bb77b17d 100644 --- a/libs/base/string_utils.hpp +++ b/libs/base/string_utils.hpp @@ -114,6 +114,20 @@ void Trim(std::string_view & sv); void Trim(std::string_view & s, std::string_view anyOf); void Trim(std::string & s, std::string_view anyOf); +template Utf8> +size_t CountChar(Utf8 const & utf8) +{ + size_t codePoints = 0; + + for (auto const c : utf8) + { + if ((c & 0xC0) != 0x80) + ++codePoints; + } + + return codePoints; +} + bool Truncate(std::string & utf8, size_t const maxTextLengthPlus1); // Replace the first match of the search substring in the input with the format string. diff --git a/libs/drape/glyph_manager.cpp b/libs/drape/glyph_manager.cpp index 864b728b6..c475677f9 100644 --- a/libs/drape/glyph_manager.cpp +++ b/libs/drape/glyph_manager.cpp @@ -19,10 +19,6 @@ #include #include #include -#include -#include -#include -#include #include FT_FREETYPE_H #include FT_MODULE_H @@ -600,8 +596,7 @@ FreetypeError constexpr g_FT_Errors[] = // For SplitText it's enough to know if the last visual (first logical) segment is RTL. allGlyphs.m_isRTL = segments.back().m_direction == HB_DIRECTION_RTL; - // TODO(AB): Check if it's slower or faster. - allGlyphs.m_glyphs.reserve(icu::UnicodeString{false, text.data(), static_cast(text.size())}.countChar32()); + allGlyphs.m_glyphs.reserve(strings::CountChar(utf8)); for (auto const & substring : segments) { diff --git a/libs/drape/harfbuzz_shaping.cpp b/libs/drape/harfbuzz_shaping.cpp index b03df65cf..153a8088c 100644 --- a/libs/drape/harfbuzz_shaping.cpp +++ b/libs/drape/harfbuzz_shaping.cpp @@ -213,7 +213,7 @@ void ReorderRTL(TextSegments & segments) TextSegments GetTextSegments(std::string_view utf8) { ASSERT(!utf8.empty(), ("Shaping of empty strings is not supported")); - ASSERT(std::string::npos == utf8.find_first_of("\r\n"), ("Shaping with line breaks is not supported", utf8)); + ASSERT(std::string::npos == utf8.find_first_of("\n"), ("Shaping with line breaks is not supported", utf8)); // TODO(AB): Can unnecessary conversion/allocation be avoided? TextSegments segments{strings::ToUtf16(utf8), {}}; diff --git a/libs/search/query_params.cpp b/libs/search/query_params.cpp index 158a05994..e7f0876c9 100644 --- a/libs/search/query_params.cpp +++ b/libs/search/query_params.cpp @@ -3,7 +3,7 @@ #include "search/ranking_utils.hpp" #include "search/token_range.hpp" -#include +#include #include namespace search @@ -15,7 +15,7 @@ namespace // All synonyms should be lowercase. /// @todo These should check the map language and use only the corresponding translation. -map> const kSynonyms = { +unordered_map> const kSynonyms = { /// @todo Should process synonyms with errors like "blvrd" -> "blvd". /// @see HouseOnStreetSynonymsWithMisprints test. {"1", {"pierwszy", "pierwsza", "un", "una", "pierwsze", "primo"}},