Replace DeclContext's vector of ScopedDecl pointers with a linked list
of ScopedDecls (using the new ScopedDecl::NextDeclInScope
pointer). Performance-wise:
- It's a net win in memory utilization, since DeclContext is now one
pointer smaller than it used to be (std::vectors are typically 3
pointers; we now use 2 pointers) and
- Parsing Cocoa.h with -fsyntax-only (with a Release-Asserts Clang)
is about 1.9% faster than before, most likely because we no longer
have the memory allocations and copying associated with the
std::vector.
I'll re-enable serialization of DeclContexts once I've sorted out the
NextDeclarator/NextDeclInScope question.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62001 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index d9765ac..cafe535 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -401,7 +401,8 @@
}
void DeclContext::DestroyDecls(ASTContext &C) {
- for (decl_iterator D = Decls.begin(); D != Decls.end(); ++D) {
+ for (decl_iterator D = decls_begin(); D != decls_end(); ++D) {
+ // FIXME: assert that this condition holds.
if ((*D)->getLexicalDeclContext() == this)
(*D)->Destroy(C);
}
@@ -515,7 +516,15 @@
void DeclContext::addDecl(ASTContext &Context, ScopedDecl *D, bool AllowLookup) {
assert(D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context");
- Decls.push_back(D);
+ assert(!D->NextDeclInScope && D != LastDecl &&
+ "Decl already inserted into a DeclContext");
+
+ if (FirstDecl) {
+ LastDecl->NextDeclInScope = D;
+ LastDecl = D;
+ } else {
+ FirstDecl = LastDecl = D;
+ }
if (AllowLookup)
D->getDeclContext()->insert(Context, D);
}
diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp
index 38af462..11577cd 100644
--- a/lib/AST/DeclSerialization.cpp
+++ b/lib/AST/DeclSerialization.cpp
@@ -124,6 +124,9 @@
//===----------------------------------------------------------------------===//
void DeclContext::EmitOutRec(Serializer& S) const {
+#if 0
+ // FIXME: it would be far easier to just serialize FirstDecl and let
+ // ScopedDecl do the work of serializing NextDeclInScope.
S.EmitInt(Decls.size());
for (decl_iterator D = decls_begin(); D != decls_end(); ++D) {
bool Owned = ((*D)->getLexicalDeclContext() == this &&
@@ -135,9 +138,12 @@
else
S.EmitPtr(*D);
}
+#endif
}
void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
+#if 0
+ // FIXME: See comment in DeclContext::EmitOutRec
unsigned NumDecls = D.ReadInt();
Decls.resize(NumDecls);
for (unsigned Idx = 0; Idx < NumDecls; ++Idx) {
@@ -147,6 +153,7 @@
else
D.ReadPtr<ScopedDecl>(Decls[Idx]);
}
+#endif
}
//===----------------------------------------------------------------------===//
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index ecf6de9..ee72a98 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -515,7 +515,7 @@
Diag(New->getLocation(), diag::err_redefinition_different_typedef)
<< New->getUnderlyingType() << Old->getUnderlyingType();
Diag(Old->getLocation(), diag::note_previous_definition);
- return Old;
+ return New;
}
if (getLangOptions().Microsoft) return New;
@@ -768,7 +768,8 @@
QualType OldCType = Context.getCanonicalType(Old->getType());
QualType NewCType = Context.getCanonicalType(New->getType());
if (OldCType != NewCType && !Context.typesAreCompatible(OldCType, NewCType)) {
- Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName();
+ Diag(New->getLocation(), diag::err_redefinition_different_type)
+ << New->getDeclName();
Diag(Old->getLocation(), diag::note_previous_definition);
return New;
}
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index f39b84c..49a8c83 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1078,6 +1078,7 @@
ObjCPropertyDecl::Optional) ?
ObjCMethodDecl::Optional :
ObjCMethodDecl::Required);
+ CD->addDecl(Context, GetterMethod);
} else
// A user declared getter will be synthesize when @synthesize of
// the property with the same name is seen in the @implementation
@@ -1108,6 +1109,7 @@
VarDecl::None,
0, 0);
SetterMethod->setMethodParams(&Argument, 1);
+ CD->addDecl(Context, SetterMethod);
} else
// A user declared setter will be synthesize when @synthesize of
// the property with the same name is seen in the @implementation
@@ -1126,14 +1128,10 @@
// double bar = [foo bar];
// }
//
- if (GetterMethod) {
- CD->addDecl(Context, GetterMethod);
+ if (GetterMethod)
AddInstanceMethodToGlobalPool(GetterMethod);
- }
- if (SetterMethod) {
- CD->addDecl(Context, SetterMethod);
+ if (SetterMethod)
AddInstanceMethodToGlobalPool(SetterMethod);
- }
}
// Note: For class/category implemenations, allMethods/allProperties is