[cfe-commits] r62391 - in /cfe/trunk/lib/Sema: Sema.h SemaLookup.cpp
Douglas Gregor
dgregor at apple.com
Fri Jan 16 17:13:25 PST 2009
Author: dgregor
Date: Fri Jan 16 19:13:24 2009
New Revision: 62391
URL: http://llvm.org/viewvc/llvm-project?rev=62391&view=rev
Log:
PODify LookupResult, for a measly 1% speedup on Cocoa.h.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaLookup.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=62391&r1=62390&r2=62391&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Jan 16 19:13:24 2009
@@ -630,10 +630,10 @@
/// getAsDecl() method. This conversion permits the common-case
/// usage in C and Objective-C where name lookup will always return
/// a single declaration.
- class LookupResult {
+ struct LookupResult {
/// The kind of entity that is actually stored within the
/// LookupResult object.
- mutable enum {
+ enum {
/// First is a single declaration (a Decl*), which may be NULL.
SingleDecl,
@@ -649,11 +649,7 @@
/// by the LookupResult. Last is non-zero to indicate that the
/// ambiguity is caused by two names found in base class
/// subobjects of different types.
- AmbiguousLookup,
-
- /// We've moved from this object. There should not be any
- /// attempts to look at its state.
- Dead
+ AmbiguousLookup
} StoredKind;
/// The first lookup result, whose contents depend on the kind of
@@ -677,7 +673,6 @@
/// Decl*.
ASTContext *Context;
- public:
/// @brief The kind of entity found by name lookup.
enum LookupKind {
/// @brief No entity found met the criteria.
@@ -721,30 +716,32 @@
AmbiguousBaseSubobjects
};
- LookupResult() : StoredKind(Dead), First(0), Last(0), Context(0) { }
-
- LookupResult(const LookupResult& Other);
-
- LookupResult(ASTContext &Context, Decl *D)
- : StoredKind(SingleDecl), First(reinterpret_cast<uintptr_t>(D)),
- Last(0), Context(&Context) { }
-
- LookupResult(ASTContext &Context,
- IdentifierResolver::iterator F, IdentifierResolver::iterator L);
-
- LookupResult(ASTContext &Context,
- DeclContext::lookup_iterator F, DeclContext::lookup_iterator L);
-
- LookupResult(ASTContext &Context, BasePaths *Paths,
- bool DifferentSubobjectTypes)
- : StoredKind(AmbiguousLookup),
- First(reinterpret_cast<uintptr_t>(Paths)),
- Last(DifferentSubobjectTypes? 1 : 0),
- Context(&Context) { }
-
- ~LookupResult();
-
- LookupResult& operator=(const LookupResult& Other);
+ static LookupResult CreateLookupResult(ASTContext &Context, Decl *D) {
+ LookupResult Result;
+ Result.StoredKind = SingleDecl;
+ Result.First = reinterpret_cast<uintptr_t>(D);
+ Result.Last = 0;
+ Result.Context = &Context;
+ return Result;
+ }
+
+ static LookupResult CreateLookupResult(ASTContext &Context,
+ IdentifierResolver::iterator F,
+ IdentifierResolver::iterator L);
+
+ static LookupResult CreateLookupResult(ASTContext &Context,
+ DeclContext::lookup_iterator F,
+ DeclContext::lookup_iterator L);
+
+ static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
+ bool DifferentSubobjectTypes) {
+ LookupResult Result;
+ Result.StoredKind = AmbiguousLookup;
+ Result.First = reinterpret_cast<uintptr_t>(Paths);
+ Result.Last = DifferentSubobjectTypes? 1 : 0;
+ Result.Context = &Context;
+ return Result;
+ }
LookupKind getKind() const;
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=62391&r1=62390&r2=62391&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Jan 16 19:13:24 2009
@@ -128,74 +128,55 @@
return false;
}
-/// @brief Moves the name-lookup results from Other to the
-/// newly-constructed LookupResult.
-Sema::LookupResult::LookupResult(const LookupResult& Other)
- : StoredKind(Other.StoredKind), First(Other.First), Last(Other.Last),
- Context(Other.Context) {
- Other.StoredKind = Dead;
-}
-
/// @brief Moves the name-lookup results from Other to this LookupResult.
-Sema::LookupResult::LookupResult(ASTContext &Context,
- IdentifierResolver::iterator F,
- IdentifierResolver::iterator L)
- : Context(&Context) {
+Sema::LookupResult
+Sema::LookupResult::CreateLookupResult(ASTContext &Context,
+ IdentifierResolver::iterator F,
+ IdentifierResolver::iterator L) {
+ LookupResult Result;
+ Result.Context = &Context;
+
if (F != L && isa<FunctionDecl>(*F)) {
IdentifierResolver::iterator Next = F;
++Next;
if (Next != L && isa<FunctionDecl>(*Next)) {
- StoredKind = OverloadedDeclFromIdResolver;
- First = F.getAsOpaqueValue();
- Last = L.getAsOpaqueValue();
- return;
+ Result.StoredKind = OverloadedDeclFromIdResolver;
+ Result.First = F.getAsOpaqueValue();
+ Result.Last = L.getAsOpaqueValue();
+ return Result;
}
}
- StoredKind = SingleDecl;
- First = reinterpret_cast<uintptr_t>(*F);
- Last = 0;
+ Result.StoredKind = SingleDecl;
+ Result.First = reinterpret_cast<uintptr_t>(*F);
+ Result.Last = 0;
+ return Result;
}
-Sema::LookupResult::LookupResult(ASTContext &Context,
- DeclContext::lookup_iterator F,
- DeclContext::lookup_iterator L)
- : Context(&Context) {
+Sema::LookupResult
+Sema::LookupResult::CreateLookupResult(ASTContext &Context,
+ DeclContext::lookup_iterator F,
+ DeclContext::lookup_iterator L) {
+ LookupResult Result;
+ Result.Context = &Context;
+
if (F != L && isa<FunctionDecl>(*F)) {
DeclContext::lookup_iterator Next = F;
++Next;
if (Next != L && isa<FunctionDecl>(*Next)) {
- StoredKind = OverloadedDeclFromDeclContext;
- First = reinterpret_cast<uintptr_t>(F);
- Last = reinterpret_cast<uintptr_t>(L);
- return;
+ Result.StoredKind = OverloadedDeclFromDeclContext;
+ Result.First = reinterpret_cast<uintptr_t>(F);
+ Result.Last = reinterpret_cast<uintptr_t>(L);
+ return Result;
}
}
- StoredKind = SingleDecl;
- First = reinterpret_cast<uintptr_t>(*F);
- Last = 0;
-}
-
-Sema::LookupResult::~LookupResult() {
- if (StoredKind == AmbiguousLookup)
- delete getBasePaths();
+ Result.StoredKind = SingleDecl;
+ Result.First = reinterpret_cast<uintptr_t>(*F);
+ Result.Last = 0;
+ return Result;
}
-Sema::LookupResult& Sema::LookupResult::operator=(const LookupResult& Other) {
- if (StoredKind == AmbiguousLookup)
- delete getBasePaths();
-
- StoredKind = Other.StoredKind;
- First = Other.First;
- Last = Other.Last;
- Context = Other.Context;
-
- Other.StoredKind = Dead;
- return *this;
-}
-
-
/// @brief Determine the result of name lookup.
Sema::LookupResult::LookupKind Sema::LookupResult::getKind() const {
switch (StoredKind) {
@@ -208,10 +189,6 @@
case AmbiguousLookup:
return Last? AmbiguousBaseSubobjectTypes : AmbiguousBaseSubobjects;
-
- case Dead:
- assert(false && "Attempt to look at a dead LookupResult");
- break;
}
// We can't ever get here.
@@ -250,9 +227,6 @@
assert(false &&
"Name lookup returned an ambiguity that could not be handled");
break;
-
- case Dead:
- assert(false && "Attempt to look at a dead LookupResult");
}
return 0;
@@ -304,7 +278,7 @@
/// ambiguities.
Sema::LookupResult
Sema::LookupName(Scope *S, DeclarationName Name, LookupCriteria Criteria) {
- if (!Name) return LookupResult(Context, 0);
+ if (!Name) return LookupResult::CreateLookupResult(Context, 0);
if (!getLangOptions().CPlusPlus) {
// Unqualified name lookup in C/Objective-C is purely lexical, so
@@ -335,7 +309,7 @@
// deep shadowing is extremely uncommon.
for (; I != IdResolver.end(); ++I)
if (Criteria.isLookupResult(*I))
- return LookupResult(Context, *I);
+ return LookupResult::CreateLookupResult(Context, *I);
} else {
// Unqualified name lookup in C++ requires looking into scopes
// that aren't strictly lexical, and therefore we walk through the
@@ -358,7 +332,7 @@
if (!S->isDeclScope(*LastI))
break;
}
- return LookupResult(Context, I, LastI);
+ return LookupResult::CreateLookupResult(Context, I, LastI);
}
}
@@ -387,7 +361,7 @@
return Result;
if (Criteria.RedeclarationOnly && !Ctx->isTransparentContext())
- return LookupResult(Context, 0);
+ return LookupResult::CreateLookupResult(Context, 0);
Ctx = Ctx->getParent();
}
@@ -402,7 +376,7 @@
if (Criteria.AllowLazyBuiltinCreation && II) {
// If this is a builtin on this (or all) targets, create the decl.
if (unsigned BuiltinID = II->getBuiltinID())
- return LookupResult(Context,
+ return LookupResult::CreateLookupResult(Context,
LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID,
S));
}
@@ -413,13 +387,14 @@
// other names in IDNS_Ordinary.
ObjCInterfaceDeclsTy::iterator IDI = ObjCInterfaceDecls.find(II);
if (IDI != ObjCInterfaceDecls.end())
- return LookupResult(Context, IDI->second);
+ return LookupResult::CreateLookupResult(Context, IDI->second);
ObjCAliasTy::iterator I = ObjCAliasDecls.find(II);
if (I != ObjCAliasDecls.end())
- return LookupResult(Context, I->second->getClassInterface());
+ return LookupResult::CreateLookupResult(Context,
+ I->second->getClassInterface());
}
}
- return LookupResult(Context, 0);
+ return LookupResult::CreateLookupResult(Context, 0);
}
/// @brief Perform qualified name lookup into a given context.
@@ -457,7 +432,7 @@
LookupCriteria Criteria) {
assert(LookupCtx && "Sema::LookupQualifiedName requires a lookup context");
- if (!Name) return LookupResult(Context, 0);
+ if (!Name) return LookupResult::CreateLookupResult(Context, 0);
// If we're performing qualified name lookup (e.g., lookup into a
// struct), find fields as part of ordinary name lookup.
@@ -468,12 +443,12 @@
DeclContext::lookup_iterator I, E;
for (llvm::tie(I, E) = LookupCtx->lookup(Name); I != E; ++I)
if (Criteria.isLookupResult(*I))
- return LookupResult(Context, I, E);
+ return LookupResult::CreateLookupResult(Context, I, E);
// If this isn't a C++ class or we aren't allowed to look into base
// classes, we're done.
if (Criteria.RedeclarationOnly || !isa<CXXRecordDecl>(LookupCtx))
- return LookupResult(Context, 0);
+ return LookupResult::CreateLookupResult(Context, 0);
// Perform lookup into our base classes.
BasePaths Paths;
@@ -482,7 +457,7 @@
// Look for this member in our base classes
if (!LookupInBases(cast<CXXRecordDecl>(LookupCtx),
MemberLookupCriteria(Name, Criteria), Paths))
- return LookupResult(Context, 0);
+ return LookupResult::CreateLookupResult(Context, 0);
// C++ [class.member.lookup]p2:
// [...] If the resulting set of declarations are not all from
@@ -508,7 +483,7 @@
// different types. This lookup is ambiguous.
BasePaths *PathsOnHeap = new BasePaths;
PathsOnHeap->swap(Paths);
- return LookupResult(Context, PathsOnHeap, true);
+ return LookupResult::CreateLookupResult(Context, PathsOnHeap, true);
} else if (SubobjectNumber != PathElement.SubobjectNumber) {
// We have a different subobject of the same type.
@@ -546,7 +521,7 @@
// subobjects. Name lookup is ambiguous.
BasePaths *PathsOnHeap = new BasePaths;
PathsOnHeap->swap(Paths);
- return LookupResult(Context, PathsOnHeap, false);
+ return LookupResult::CreateLookupResult(Context, PathsOnHeap, false);
}
}
@@ -554,11 +529,11 @@
// If we found a function declaration, return an overload set.
if (isa<FunctionDecl>(*Paths.front().Decls.first))
- return LookupResult(Context,
+ return LookupResult::CreateLookupResult(Context,
Paths.front().Decls.first, Paths.front().Decls.second);
// We found a non-function declaration; return a single declaration.
- return LookupResult(Context, *Paths.front().Decls.first);
+ return LookupResult::CreateLookupResult(Context, *Paths.front().Decls.first);
}
/// @brief Performs name lookup for a name that was parsed in the
@@ -643,5 +618,7 @@
Diag(D->getLocation(), diag::note_ambiguous_member_found);
}
+ delete Paths;
+
return true;
}
More information about the cfe-commits
mailing list