diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-20 01:10:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-20 01:10:07 +0000 |
commit | 29578f3f4127d444b84aac5a15a30e7cf3e80b9f (patch) | |
tree | 5c98c335afa257641b28a77e4b777ece49593203 | |
parent | 33f219d1a9ed98e0a9126d3a9e265fcbc9f260aa (diff) | |
download | bcm5719-llvm-29578f3f4127d444b84aac5a15a30e7cf3e80b9f.tar.gz bcm5719-llvm-29578f3f4127d444b84aac5a15a30e7cf3e80b9f.zip |
make the redeclaration case faster for the common instance of a redeclaration
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
llvm-svn: 65096
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 9b277fe99ce..a35dcc28bb6 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -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; + } } } |