summaryrefslogtreecommitdiff
path: root/tools/aapt2/StringPool.cpp
diff options
context:
space:
mode:
authory <rtmitchell@google.com>2018-04-16 18:13:14 -0700
committerRyan Mitchell <rtmitchell@google.com>2018-04-18 20:58:50 +0000
commit4602926f83d7aa3b52b190122955b5b0d6d8089d (patch)
tree4b483cd443fb3b1b9f7eb03d4d326c22da213998 /tools/aapt2/StringPool.cpp
parent34a0b18a5c730e4fa16e27c63ed0cd79a6df188e (diff)
AAPT2: Modified StringPool uniqueness detection #2
b/77862560 detected that when converting an apk to binary using aapt2, all resource ids of attributes that have been replaced with resource identifiers become set to the identifier of the first attribute. This is because the attribute names are all empty because the names are not necessary since the resource ids are present. The empty attribute names all map to the same string pool reference and cause all the ids to be the first empty string into the string pool. The ag/3897499 approach to fix the specified bug was extremely inefficient and caused hour long builds. This change takes advantage of the multimap data structure to do lookups efficiently. Bug: 77862560 Test: Converted apk in listed bug from proto to binary and observed correct resource ids and correct badging. Also built the Android tree to check for regressions in build time. Change-Id: I27a9ee4ffbed8b9ff6f238ad315cdf87b588947c
Diffstat (limited to 'tools/aapt2/StringPool.cpp')
-rw-r--r--tools/aapt2/StringPool.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/aapt2/StringPool.cpp b/tools/aapt2/StringPool.cpp
index b0ce9e1ec947..b37e1fbd9693 100644
--- a/tools/aapt2/StringPool.cpp
+++ b/tools/aapt2/StringPool.cpp
@@ -172,9 +172,11 @@ StringPool::Ref StringPool::MakeRef(const StringPiece& str, const Context& conte
StringPool::Ref StringPool::MakeRefImpl(const StringPiece& str, const Context& context,
bool unique) {
if (unique) {
- auto iter = indexed_strings_.find(str);
- if (iter != std::end(indexed_strings_)) {
- return Ref(iter->second);
+ auto range = indexed_strings_.equal_range(str);
+ for (auto iter = range.first; iter != range.second; ++iter) {
+ if (context.priority == iter->second->context.priority) {
+ return Ref(iter->second);
+ }
}
}