[res] Optimize name lookups in idmap service
The most common operation when build idmaps is to find the
resource ID by name. This is the least optimized operation
in the current resources data structures, as they only
expect ID -> value lookups
This change adds an optional flag that creates a name->ID
hash map inside ResStringPool, and use it when loading
APKs in idmap2d
Bug: 282215580
Test: build + boot + perf record
Change-Id: I82f4d684cb48e2dcddcd677b882b11497c1c13b1
diff --git a/libs/androidfw/LoadedArsc.cpp b/libs/androidfw/LoadedArsc.cpp
index 02707e0..d9166a1 100644
--- a/libs/androidfw/LoadedArsc.cpp
+++ b/libs/androidfw/LoadedArsc.cpp
@@ -454,7 +454,8 @@
std::unique_ptr<const LoadedPackage> LoadedPackage::Load(const Chunk& chunk,
package_property_t property_flags) {
ATRACE_NAME("LoadedPackage::Load");
- std::unique_ptr<LoadedPackage> loaded_package(new LoadedPackage());
+ const bool optimize_name_lookups = (property_flags & PROPERTY_OPTIMIZE_NAME_LOOKUPS) != 0;
+ std::unique_ptr<LoadedPackage> loaded_package(new LoadedPackage(optimize_name_lookups));
// typeIdOffset was added at some point, but we still must recognize apps built before this
// was added.