diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-04 05:35:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-04 05:35:38 +0000 |
commit | 1a84994c4617af3971ac889a192a10647131fa1b (patch) | |
tree | 9eaec2050ff318cdf042d07dfe1594cd4bc1492a /clang/lib/Basic/IdentifierTable.cpp | |
parent | 7b26b293516b67fe5644ec5d47f254341c4d8991 (diff) | |
download | bcm5719-llvm-1a84994c4617af3971ac889a192a10647131fa1b.tar.gz bcm5719-llvm-1a84994c4617af3971ac889a192a10647131fa1b.zip |
allocate MultiKeywordSelector's out of a bump pointer allocator instead of malloc.
This has two advantages 1) no more leaking them, 2) fewer calls to malloc.
This changes us from calling malloc 3685/1390/883/2974/1185 times respectively on
16/20/24/28/32 byte objects when parsing cocoa.h with pth and -disable-free to
calling it 2816/1020/702/2903/1168 times each respectively.
llvm-svn: 66017
Diffstat (limited to 'clang/lib/Basic/IdentifierTable.cpp')
-rw-r--r-- | clang/lib/Basic/IdentifierTable.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 0f0b4f9b8c6..bd4facd8355 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -363,38 +363,50 @@ std::string Selector::getAsString() const { } +namespace { + struct SelectorTableImpl { + llvm::FoldingSet<MultiKeywordSelector> Table; + llvm::BumpPtrAllocator Allocator; + }; +} // end anonymous namespace. + +static SelectorTableImpl &getSelectorTableImpl(void *P) { + return *static_cast<SelectorTableImpl*>(P); +} + + Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) { if (nKeys < 2) return Selector(IIV[0], nKeys); - llvm::FoldingSet<MultiKeywordSelector> *SelTab; - - SelTab = static_cast<llvm::FoldingSet<MultiKeywordSelector> *>(Impl); + SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl); // Unique selector, to guarantee there is one per name. llvm::FoldingSetNodeID ID; MultiKeywordSelector::Profile(ID, IIV, nKeys); void *InsertPos = 0; - if (MultiKeywordSelector *SI = SelTab->FindNodeOrInsertPos(ID, InsertPos)) + if (MultiKeywordSelector *SI = + SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos)) return Selector(SI); // MultiKeywordSelector objects are not allocated with new because they have a // variable size array (for parameter types) at the end of them. - MultiKeywordSelector *SI = - (MultiKeywordSelector*)malloc(sizeof(MultiKeywordSelector) + - nKeys*sizeof(IdentifierInfo *)); + unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *); + MultiKeywordSelector *SI = + (MultiKeywordSelector*)SelTabImpl.Allocator.Allocate(Size, + llvm::alignof<MultiKeywordSelector>()); new (SI) MultiKeywordSelector(nKeys, IIV); - SelTab->InsertNode(SI, InsertPos); + SelTabImpl.Table.InsertNode(SI, InsertPos); return Selector(SI); } SelectorTable::SelectorTable() { - Impl = new llvm::FoldingSet<MultiKeywordSelector>; + Impl = new SelectorTableImpl(); } SelectorTable::~SelectorTable() { - delete static_cast<llvm::FoldingSet<MultiKeywordSelector> *>(Impl); + delete &getSelectorTableImpl(Impl); } //===----------------------------------------------------------------------===// |