diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-02-16 09:31:36 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-02-16 09:31:36 +0000 |
commit | fd035e6496665b1f1197868e21cb0a4594e8db6e (patch) | |
tree | 53010172e19c77ea447bcd89e117cda052ab52e0 /lib/Sema/IdentifierResolver.cpp | |
parent | 2fce988e86bc01829142e4362d4eff1af0925147 (diff) | |
download | FreeBSD-src-fd035e6496665b1f1197868e21cb0a4594e8db6e.zip FreeBSD-src-fd035e6496665b1f1197868e21cb0a4594e8db6e.tar.gz |
Update clang to r96341.
Diffstat (limited to 'lib/Sema/IdentifierResolver.cpp')
-rw-r--r-- | lib/Sema/IdentifierResolver.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index bff4751..b09526e 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -14,8 +14,6 @@ #include "IdentifierResolver.h" #include "clang/Basic/LangOptions.h" -#include <list> -#include <vector> using namespace clang; @@ -27,14 +25,31 @@ using namespace clang; /// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each /// individual IdDeclInfo to heap. class IdentifierResolver::IdDeclInfoMap { - static const unsigned int VECTOR_SIZE = 512; - // Holds vectors of IdDeclInfos that serve as 'pools'. - // New vectors are added when the current one is full. - std::list< std::vector<IdDeclInfo> > IDIVecs; + static const unsigned int POOL_SIZE = 512; + + /// We use our own linked-list implementation because it is sadly + /// impossible to add something to a pre-C++0x STL container without + /// a completely unnecessary copy. + struct IdDeclInfoPool { + IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {} + + IdDeclInfoPool *Next; + IdDeclInfo Pool[POOL_SIZE]; + }; + + IdDeclInfoPool *CurPool; unsigned int CurIndex; public: - IdDeclInfoMap() : CurIndex(VECTOR_SIZE) {} + IdDeclInfoMap() : CurPool(0), CurIndex(POOL_SIZE) {} + + ~IdDeclInfoMap() { + IdDeclInfoPool *Cur = CurPool; + while (IdDeclInfoPool *P = Cur) { + Cur = Cur->Next; + delete P; + } + } /// Returns the IdDeclInfo associated to the DeclarationName. /// It creates a new IdDeclInfo if one was not created before for this id. @@ -235,14 +250,11 @@ IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) { if (Ptr) return *toIdDeclInfo(Ptr); - if (CurIndex == VECTOR_SIZE) { - // Add a IdDeclInfo vector 'pool' - IDIVecs.push_back(std::vector<IdDeclInfo>()); - // Fill the vector - IDIVecs.back().resize(VECTOR_SIZE); + if (CurIndex == POOL_SIZE) { + CurPool = new IdDeclInfoPool(CurPool); CurIndex = 0; } - IdDeclInfo *IDI = &IDIVecs.back()[CurIndex]; + IdDeclInfo *IDI = &CurPool->Pool[CurIndex]; Name.setFETokenInfo(reinterpret_cast<void*>( reinterpret_cast<uintptr_t>(IDI) | 0x1) ); |