Merge "AAPT2: Modified StringPool uniqueness detection #2" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b2182c412c
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,17 @@ TEST(StringPoolTest, DoNotInsertNewDuplicateString) {
|
||||
EXPECT_THAT(pool.size(), Eq(1u));
|
||||
}
|
||||
|
||||
TEST(StringPoolTest, DoNotDedupeSameStringDifferentPriority) {
|
||||
StringPool pool;
|
||||
|
||||
StringPool::Ref ref_a = pool.MakeRef("wut", StringPool::Context(0x81010001));
|
||||
StringPool::Ref ref_b = pool.MakeRef("wut", StringPool::Context(0x81010002));
|
||||
|
||||
EXPECT_THAT(*ref_a, Eq("wut"));
|
||||
EXPECT_THAT(*ref_b, Eq("wut"));
|
||||
EXPECT_THAT(pool.size(), Eq(2u));
|
||||
}
|
||||
|
||||
TEST(StringPoolTest, MaintainInsertionOrderIndex) {
|
||||
StringPool pool;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user