From 984a84eed846b5c04265057075d574b440564168 Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Thu, 20 Mar 2025 12:17:05 -0700 Subject: [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 --- libs/androidfw/LoadedArsc.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'libs/androidfw/LoadedArsc.cpp') 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 LoadedPackage::CollectConfigurations( return {}; } -void LoadedPackage::CollectLocales(bool canonicalize, std::set* 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); + } } } } -- cgit v1.2.3-59-g8ed1b