diff options
author | Diego Wilson <diegowilson@google.com> | 2018-11-20 11:38:33 -0800 |
---|---|---|
committer | Bill Peckham <bpeckham@google.com> | 2018-12-05 17:57:49 -0800 |
commit | b76115be4efabffaa6febc57cec47acc2f933c79 (patch) | |
tree | 3c75adb1327eb78655b3bd8e1fd47db1a650b233 /tools/aapt2/StringPool.cpp | |
parent | b1a0dd53db11fb24b5937212720aa92fa70b4fdd (diff) | |
parent | 5a05000482abc03a74556ae0e289172eb0ae5607 (diff) |
Merge QP1A.181119.002
Change-Id: Ieb6ae3730e8b01f867f9b5120de1ab3067653d21
Diffstat (limited to 'tools/aapt2/StringPool.cpp')
-rw-r--r-- | tools/aapt2/StringPool.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tools/aapt2/StringPool.cpp b/tools/aapt2/StringPool.cpp index 8eabd3225d87..a8c26668b3a5 100644 --- a/tools/aapt2/StringPool.cpp +++ b/tools/aapt2/StringPool.cpp @@ -165,12 +165,13 @@ StringPool::Ref StringPool::MakeRef(const StringPiece& str) { return MakeRefImpl(str, Context{}, true); } -StringPool::Ref StringPool::MakeRef(const StringPiece& str, const Context& context) { - return MakeRefImpl(str, context, true); +StringPool::Ref StringPool::MakeRef(const StringPiece& str, const Context& context, + Maybe<size_t> index) { + return MakeRefImpl(str, context, true, index); } StringPool::Ref StringPool::MakeRefImpl(const StringPiece& str, const Context& context, - bool unique) { + bool unique, Maybe<size_t> index) { if (unique) { auto range = indexed_strings_.equal_range(str); for (auto iter = range.first; iter != range.second; ++iter) { @@ -180,15 +181,26 @@ StringPool::Ref StringPool::MakeRefImpl(const StringPiece& str, const Context& c } } + const size_t size = strings_.size(); + // Insert the string at the end of the string vector if no index is specified + const size_t insertion_index = index ? index.value() : size; + std::unique_ptr<Entry> entry(new Entry()); entry->value = str.to_string(); entry->context = context; - entry->index_ = strings_.size(); + entry->index_ = insertion_index; entry->ref_ = 0; entry->pool_ = this; Entry* borrow = entry.get(); - strings_.emplace_back(std::move(entry)); + if (insertion_index == size) { + strings_.emplace_back(std::move(entry)); + } else { + // Allocate enough space for the string at the index + strings_.resize(std::max(insertion_index + 1, size)); + strings_[insertion_index] = std::move(entry); + } + indexed_strings_.insert(std::make_pair(StringPiece(borrow->value), borrow)); return Ref(borrow); } |