]> granicus.if.org Git - clang/commitdiff
make the redeclaration case faster for the common instance of a redeclaration
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 01:10:07 +0000 (01:10 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 01:10:07 +0000 (01:10 +0000)
where there is exactly one existing declaration.  This is common.

this speeds up clang about 3% on cocoa.h for me 0.165 -> 0.160s

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65096 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclBase.cpp

index 9b277fe99ce4c3cb36c6b70d66e57877d1b0114c..a35dcc28bb6bbc6bf62b3deafd2ffd29f3dc041f 100644 (file)
@@ -566,15 +566,26 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D) {
     return;
   }
 
+  // If it is possible that this is a redeclaration, check to see if there is
+  // already a decl for which declarationReplaces returns true.  If there is
+  // one, just replace it and return.
   if (MayBeRedeclaration) {
-    // Determine if this declaration is actually a redeclaration.
-    std::vector<NamedDecl *>::iterator Redecl
-      = std::find_if(DeclNameEntries.begin(), DeclNameEntries.end(),
-                   std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
-                                D));
-    if (Redecl != DeclNameEntries.end()) {
-      *Redecl = D;
-      return;
+    // Most decls only have one entry in their list, special case it.
+    if (DeclNameEntries.size() == 1) {
+      if (D->declarationReplaces(DeclNameEntries[0])) {
+        DeclNameEntries[0] = D;
+        return;
+      }
+    } else {
+      // Determine if this declaration is actually a redeclaration.
+      std::vector<NamedDecl *>::iterator Redecl
+        = std::find_if(DeclNameEntries.begin(), DeclNameEntries.end(),
+                     std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
+                                  D));
+      if (Redecl != DeclNameEntries.end()) {
+        *Redecl = D;
+        return;
+      }
     }
   }