From cd7720a03f91f026bef40ac94ba9b85a0125c379 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 20 Nov 2012 23:23:57 +0000 Subject: [PATCH] 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. llvm-svn: 168394 --- clang/include/clang/AST/Decl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 087a585..020f3b0 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/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); -- 2.7.4