diff options
author | 2022-11-14 22:26:10 -0800 | |
---|---|---|
committer | 2022-11-30 18:04:32 -0800 | |
commit | dbce35604cdadfadc47492d7f75576365726d323 (patch) | |
tree | 504acb1394832a4e068150fc76b62baa59c477b7 /libs/androidfw/AssetManager2.cpp | |
parent | 591895bd28f3073dfeebf6bcfb0fc18491e54809 (diff) |
[res] Reuse memory in RebuildFilterList()
Original code deleted all allocated arrays to new' them back
right away. Now, with new methods in ByteBucketArray the code
only clears the vectors without releasing the capacity, and then
proceeds to free the vectors that ended up not being used.
This speeds up theme changes (accents / dark theme etc) by
about 20%
+ small other improvements in ByteBucketArray
Bug: 237583012
Test: build + UTs + boot
Change-Id: I158af793e5476b4f3215dbe602daa872136d633f
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r-- | libs/androidfw/AssetManager2.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 27b121b0cccc..2864c6843633 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -1356,21 +1356,22 @@ base::expected<uint32_t, NullOrIOError> AssetManager2::GetResourceId( void AssetManager2::RebuildFilterList() { for (PackageGroup& group : package_groups_) { - for (ConfiguredPackage& impl : group.packages_) { - impl.filtered_configs_.clear(); - + for (ConfiguredPackage& package : group.packages_) { + package.filtered_configs_.forEachItem([](auto, auto& fcg) { fcg.type_entries.clear(); }); // Create the filters here. - impl.loaded_package_->ForEachTypeSpec([&](const TypeSpec& type_spec, uint8_t type_id) { + package.loaded_package_->ForEachTypeSpec([&](const TypeSpec& type_spec, uint8_t type_id) { FilteredConfigGroup* group = nullptr; for (const auto& type_entry : type_spec.type_entries) { if (type_entry.config.match(configuration_)) { if (!group) { - group = &impl.filtered_configs_.editItemAt(type_id - 1); + group = &package.filtered_configs_.editItemAt(type_id - 1); } group->type_entries.push_back(&type_entry); } } }); + package.filtered_configs_.trimBuckets( + [](const auto& fcg) { return fcg.type_entries.empty(); }); } } } |