From: Chris Lattner Date: Thu, 19 Feb 2009 07:05:16 +0000 (+0000) Subject: only do one DenseMap lookup instead of two (one to find out if there is X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f82328852c80a51b36a146de6ef5fd5b15e72c37;p=clang only do one DenseMap lookup instead of two (one to find out if there is already an entry and one to insert). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65030 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index c03c36048a..d244637af7 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -561,19 +561,19 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { // Insert this declaration into the map. StoredDeclsMap *Map = static_cast(LookupPtr.getPointer()); - StoredDeclsMap::iterator Pos = Map->find(D->getDeclName()); - if (Pos == Map->end()) { - (*Map)[D->getDeclName()].push_back(D); + std::vector &DeclNameEntries = (*Map)[D->getDeclName()]; + if (DeclNameEntries.empty()) { + DeclNameEntries.push_back(D); return; } if (MayBeRedeclaration) { // Determine if this declaration is actually a redeclaration. std::vector::iterator Redecl - = std::find_if(Pos->second.begin(), Pos->second.end(), + = std::find_if(DeclNameEntries.begin(), DeclNameEntries.end(), std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces), D)); - if (Redecl != Pos->second.end()) { + if (Redecl != DeclNameEntries.end()) { *Redecl = D; return; } @@ -582,14 +582,14 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) { // Put this declaration into the appropriate slot. if (isa(D) || D->getIdentifierNamespace() == Decl::IDNS_Tag || - Pos->second.empty()) - Pos->second.push_back(D); - else if (Pos->second.back()->getIdentifierNamespace() == Decl::IDNS_Tag) { - NamedDecl *TagD = Pos->second.back(); - Pos->second.back() = D; - Pos->second.push_back(TagD); + DeclNameEntries.empty()) + DeclNameEntries.push_back(D); + else if (DeclNameEntries.back()->getIdentifierNamespace() == Decl::IDNS_Tag) { + NamedDecl *TagD = DeclNameEntries.back(); + DeclNameEntries.back() = D; + DeclNameEntries.push_back(TagD); } else - Pos->second.push_back(D); + DeclNameEntries.push_back(D); } /// Returns iterator range [First, Last) of UsingDirectiveDecls stored within