diff options
author | 2025-03-20 12:17:05 -0700 | |
---|---|---|
committer | 2025-03-20 22:38:25 -0700 | |
commit | 984a84eed846b5c04265057075d574b440564168 (patch) | |
tree | 347bc58ec194f0670dbf5f6612079fc8f4fa9b99 /libs/androidfw/LoadedArsc.cpp | |
parent | c74a0961123efd89b350476e6d7a49b623e1d798 (diff) |
[res] A bit more efficient locale collection
Don't copy the string unless it's a new locale, and limit
the allocations as well
Test: unit tests
Flag: EXEMPT minor performance improvement
Change-Id: Icfe433ab211a0ca22882bd579415a96dc40db30a
Diffstat (limited to 'libs/androidfw/LoadedArsc.cpp')
-rw-r--r-- | libs/androidfw/LoadedArsc.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libs/androidfw/LoadedArsc.cpp b/libs/androidfw/LoadedArsc.cpp index d9166a16cdea..7cebb6d79502 100644 --- a/libs/androidfw/LoadedArsc.cpp +++ b/libs/androidfw/LoadedArsc.cpp @@ -361,14 +361,18 @@ base::expected<std::monostate, IOError> LoadedPackage::CollectConfigurations( return {}; } -void LoadedPackage::CollectLocales(bool canonicalize, std::set<std::string>* out_locales) const { - char temp_locale[RESTABLE_MAX_LOCALE_LEN]; +void LoadedPackage::CollectLocales(bool canonicalize, + Locales* out_locales) const { for (const auto& type_spec : type_specs_) { for (const auto& type_entry : type_spec.second.type_entries) { if (type_entry.config.locale != 0) { + char temp_locale[RESTABLE_MAX_LOCALE_LEN]; type_entry.config.getBcp47Locale(temp_locale, canonicalize); - std::string locale(temp_locale); - out_locales->insert(std::move(locale)); + auto locale_sv = std::string_view(temp_locale); + if (auto it = out_locales->lower_bound(locale_sv); + it == out_locales->end() || *it != locale_sv) { + out_locales->emplace_hint(it, locale_sv); + } } } } |