diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2018-08-27 11:24:04 -0700 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2018-08-27 22:35:34 +0000 |
commit | 8d4ee973fa631c13ad458a3b906d8c1319fe0913 (patch) | |
tree | 52bdaa2fda135ea05a60237c281981012bcbc0c7 /tools/aapt2/ResourceTable.cpp | |
parent | 342df6ddd178d55aa94e01ff94e5be00457f3440 (diff) |
AAPT2: Fix resource table load time regression
A previous change (deee395) caused duplicate entries to be created for
entries eith entry ids greater than 0x0ff. This is because the wrong
data type was used (uint8_t instead of uint16_t). This made loading in
resources slower as well since more entries had to be iterated over.
Bug: 36051266
Test: Dumping all resources in 700 apks found in the android tree took 1
minute instead of 5 minutes. Created a test in aapt2_tests.
Change-Id: I1c3d830da517a56ac3496221dbe605c72e0c6014
Diffstat (limited to 'tools/aapt2/ResourceTable.cpp')
-rw-r--r-- | tools/aapt2/ResourceTable.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp index 58b5e8f0212c..23322ab277bf 100644 --- a/tools/aapt2/ResourceTable.cpp +++ b/tools/aapt2/ResourceTable.cpp @@ -51,7 +51,7 @@ static bool less_than_struct_with_name(const std::unique_ptr<T>& lhs, const Stri template <typename T> static bool less_than_struct_with_name_and_id(const std::unique_ptr<T>& lhs, - const std::pair<StringPiece, Maybe<uint8_t>>& rhs) { + const std::pair<StringPiece, Maybe<uint16_t>>& rhs) { int name_cmp = lhs->name.compare(0, lhs->name.size(), rhs.first.data(), rhs.first.size()); return name_cmp < 0 || (name_cmp == 0 && rhs.second && lhs->id < rhs.second); } @@ -141,7 +141,7 @@ ResourceTableType* ResourceTablePackage::FindOrCreateType(ResourceType type, return types.emplace(iter, std::move(new_type))->get(); } -ResourceEntry* ResourceTableType::FindEntry(const StringPiece& name, const Maybe<uint8_t> id) { +ResourceEntry* ResourceTableType::FindEntry(const StringPiece& name, const Maybe<uint16_t> id) { const auto last = entries.end(); auto iter = std::lower_bound(entries.begin(), last, std::make_pair(name, id), less_than_struct_with_name_and_id<ResourceEntry>); @@ -152,7 +152,7 @@ ResourceEntry* ResourceTableType::FindEntry(const StringPiece& name, const Maybe } ResourceEntry* ResourceTableType::FindOrCreateEntry(const StringPiece& name, - const Maybe<uint8_t> id) { + const Maybe<uint16_t > id) { auto last = entries.end(); auto iter = std::lower_bound(entries.begin(), last, std::make_pair(name, id), less_than_struct_with_name_and_id<ResourceEntry>); @@ -450,7 +450,7 @@ bool ResourceTable::AddResourceImpl(const ResourceNameRef& name, const ResourceI } ResourceEntry* entry = type->FindOrCreateEntry(name.entry, use_id ? res_id.entry_id() - : Maybe<uint8_t>()); + : Maybe<uint16_t>()); // Check for entries appearing twice with two different entry ids if (check_id && entry->id && entry->id.value() != res_id.entry_id()) { @@ -561,7 +561,7 @@ bool ResourceTable::SetVisibilityImpl(const ResourceNameRef& name, const Visibil } ResourceEntry* entry = type->FindOrCreateEntry(name.entry, use_id ? res_id.entry_id() - : Maybe<uint8_t>()); + : Maybe<uint16_t>()); // Check for entries appearing twice with two different entry ids if (check_id && entry->id && entry->id.value() != res_id.entry_id()) { |