diff options
author | Craig Topper <craig.topper@gmail.com> | 2017-05-29 21:49:37 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2017-05-29 21:49:37 +0000 |
commit | 04877f744d8e0dd79fec859096934163483a41dc (patch) | |
tree | 220956afa9db04eba3e9acbab711dd7073c30277 /lib/TableGen | |
parent | 70ac7747fab767c79b67a3e289f907fea27e23de (diff) |
[TableGen] Use StringMap instead of DenseMap<StringRef> to unique CodeInit and StringInit objects. Override the allocator to keep using the BumpPtrAllocator. NFCI
StringMap is better suited to mapping strings than a DenseMap.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304178 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen')
-rw-r--r-- | lib/TableGen/Record.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 474633a5b31..f07208b1fb9 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -405,27 +405,21 @@ IntInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const { } CodeInit *CodeInit::get(StringRef V) { - static DenseMap<StringRef, CodeInit*> ThePool; + static StringMap<CodeInit*, BumpPtrAllocator &> ThePool(Allocator); - auto I = ThePool.insert(std::make_pair(V, nullptr)); - if (I.second) { - StringRef VCopy = V.copy(Allocator); - I.first->first = VCopy; - I.first->second = new(Allocator) CodeInit(VCopy); - } - return I.first->second; + auto &Entry = *ThePool.insert(std::make_pair(V, nullptr)).first; + if (!Entry.second) + Entry.second = new(Allocator) CodeInit(Entry.getKey()); + return Entry.second; } StringInit *StringInit::get(StringRef V) { - static DenseMap<StringRef, StringInit*> ThePool; + static StringMap<StringInit*, BumpPtrAllocator &> ThePool(Allocator); - auto I = ThePool.insert(std::make_pair(V, nullptr)); - if (I.second) { - StringRef VCopy = V.copy(Allocator); - I.first->first = VCopy; - I.first->second = new(Allocator) StringInit(VCopy); - } - return I.first->second; + auto &Entry = *ThePool.insert(std::make_pair(V, nullptr)).first; + if (!Entry.second) + Entry.second = new(Allocator) StringInit(Entry.getKey()); + return Entry.second; } Init *StringInit::convertInitializerTo(RecTy *Ty) const { |