Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8751b6ee authored by Ryan Mitchell's avatar Ryan Mitchell Committed by android-build-merger
Browse files

Merge "AAPT2: Modified StringPool uniqueness detection #2" into pi-dev

am: b2182c41

Change-Id: Ib7829b0203134eecdfd59a3dcd1e78b8fbdd39b4
parents ed474ff1 b2182c41
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -172,11 +172,13 @@ 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_)) {
    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);
      }
    }
  }

  std::unique_ptr<Entry> entry(new Entry());
  entry->value = str.to_string();
+11 −0
Original line number Diff line number Diff line
@@ -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;