[cfe-commits] r65096 - /cfe/trunk/lib/AST/DeclBase.cpp
Chris Lattner
sabre at nondot.org
Thu Feb 19 17:10:07 PST 2009
Author: lattner
Date: Thu Feb 19 19:10:07 2009
New Revision: 65096
URL: http://llvm.org/viewvc/llvm-project?rev=65096&view=rev
Log:
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
Modified:
cfe/trunk/lib/AST/DeclBase.cpp
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=65096&r1=65095&r2=65096&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 19 19:10:07 2009
@@ -566,15 +566,26 @@
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;
+ }
}
}
More information about the cfe-commits
mailing list