[cfe-commits] r65030 - /cfe/trunk/lib/AST/DeclBase.cpp

Chris Lattner sabre at nondot.org
Wed Feb 18 23:05:17 PST 2009


Author: lattner
Date: Thu Feb 19 01:05:16 2009
New Revision: 65030

URL: http://llvm.org/viewvc/llvm-project?rev=65030&view=rev
Log:
only do one DenseMap lookup instead of two (one to find out if there is
already an entry and one to insert).

Modified:
    cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=65030&r1=65029&r2=65030&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 19 01:05:16 2009
@@ -561,19 +561,19 @@
 
   // Insert this declaration into the map.
   StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(LookupPtr.getPointer());
-  StoredDeclsMap::iterator Pos = Map->find(D->getDeclName());
-  if (Pos == Map->end()) {
-    (*Map)[D->getDeclName()].push_back(D);
+  std::vector<NamedDecl *> &DeclNameEntries = (*Map)[D->getDeclName()];
+  if (DeclNameEntries.empty()) {
+    DeclNameEntries.push_back(D);
     return;
   }
   
   if (MayBeRedeclaration) {
     // Determine if this declaration is actually a redeclaration.
     std::vector<NamedDecl *>::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 @@
   // Put this declaration into the appropriate slot.
   if (isa<UsingDirectiveDecl>(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





More information about the cfe-commits mailing list