]> granicus.if.org Git - clang/commitdiff
Don't walk a linked list twice in the same function. On my machine this takes
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 20 Nov 2012 23:23:57 +0000 (23:23 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 20 Nov 2012 23:23:57 +0000 (23:23 +0000)
"clang -cc1" on a file with 10k repetitions of
extern int no_such_variable;
from 1.434s to 1.133s.

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

include/clang/AST/Decl.h

index 087a58587471fccaddbb48ed3e868c3d0c1a37c2..020f3b05fc84df88ac1ed0a3b85572d0b8991762 100644 (file)
@@ -3299,10 +3299,10 @@ void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) {
     // Point to previous. Make sure that this is actually the most recent
     // redeclaration, or we can build invalid chains. If the most recent
     // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
-    RedeclLink = PreviousDeclLink(
-                   llvm::cast<decl_type>(PrevDecl->getMostRecentDecl()));
     First = PrevDecl->getFirstDeclaration();
     assert(First->RedeclLink.NextIsLatest() && "Expected first");
+    decl_type *MostRecent = First->RedeclLink.getNext();
+    RedeclLink = PreviousDeclLink(llvm::cast<decl_type>(MostRecent));
   } else {
     // Make this first.
     First = static_cast<decl_type*>(this);