From: Rafael Espindola Date: Tue, 20 Nov 2012 23:23:57 +0000 (+0000) Subject: Don't walk a linked list twice in the same function. On my machine this takes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=289994c1e7f965f2556b8b566738396659066669;p=clang Don't walk a linked list twice in the same function. On my machine this takes "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 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 087a585874..020f3b05fc 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -3299,10 +3299,10 @@ void Redeclarable::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(PrevDecl->getMostRecentDecl())); First = PrevDecl->getFirstDeclaration(); assert(First->RedeclLink.NextIsLatest() && "Expected first"); + decl_type *MostRecent = First->RedeclLink.getNext(); + RedeclLink = PreviousDeclLink(llvm::cast(MostRecent)); } else { // Make this first. First = static_cast(this);