Merge "AAPT: Modified StringPool uniqueness detection" into pi-dev
diff --git a/tools/aapt2/StringPool.cpp b/tools/aapt2/StringPool.cpp
index b0ce9e1..73a8259 100644
--- a/tools/aapt2/StringPool.cpp
+++ b/tools/aapt2/StringPool.cpp
@@ -172,9 +172,10 @@
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);
+ for (auto& indexed_str : indexed_strings_) {
+ if (str == indexed_str.first && context.priority == indexed_str.second->context.priority) {
+ return Ref(indexed_str.second);
+ }
}
}
diff --git a/tools/aapt2/StringPool_test.cpp b/tools/aapt2/StringPool_test.cpp
index 58a03de..5f7d3d6 100644
--- a/tools/aapt2/StringPool_test.cpp
+++ b/tools/aapt2/StringPool_test.cpp
@@ -61,6 +61,17 @@
EXPECT_THAT(pool.size(), Eq(1u));
}
+TEST(StringPoolTest, DoNotDedupeSameStringDifferentPriority) {
+ StringPool pool;
+
+ StringPool::Ref ref_a = pool.MakeRef("wut", StringPool::Context(1));
+ StringPool::Ref ref_b = pool.MakeRef("wut", StringPool::Context(2));
+
+ EXPECT_THAT(*ref_a, Eq("wut"));
+ EXPECT_THAT(*ref_b, Eq("wut"));
+ EXPECT_THAT(pool.size(), Eq(2u));
+}
+
TEST(StringPoolTest, MaintainInsertionOrderIndex) {
StringPool pool;
@@ -292,7 +303,6 @@
}
}
-
TEST(StringPoolTest, MaxEncodingLength) {
StdErrDiagnostics diag;
using namespace android; // For NO_ERROR on Windows.