aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Type.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-02-08 22:59:26 +0000
committerDouglas Gregor <dgregor@apple.com>2010-02-08 22:59:26 +0000
commitfd6a0887a099256c35a5b23e9afd517ffe95fa0a (patch)
tree6990fc590f9aab0df25d09bfcf9d23ae0514c082 /lib/AST/Type.cpp
parente86bcf0d9ea62cc75e545787896083f8a6bc81a1 (diff)
Eliminate a pointer of storage in each ObjCInterfaceType and
ObjCObjectPointerType AST node by allocating the list of protocols after the type node itself. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95597 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r--lib/AST/Type.cpp42
1 files changed, 15 insertions, 27 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 92498be2f5..52d734ca7e 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -339,21 +339,18 @@ const RecordType *Type::getAsUnionType() const {
return 0;
}
-ObjCInterfaceType::ObjCInterfaceType(ASTContext &Ctx, QualType Canonical,
+ObjCInterfaceType::ObjCInterfaceType(QualType Canonical,
ObjCInterfaceDecl *D,
ObjCProtocolDecl **Protos, unsigned NumP) :
Type(ObjCInterface, Canonical, /*Dependent=*/false),
- Decl(D), Protocols(0), NumProtocols(NumP)
+ Decl(D), NumProtocols(NumP)
{
- if (NumProtocols) {
- Protocols = new (Ctx) ObjCProtocolDecl*[NumProtocols];
- memcpy(Protocols, Protos, NumProtocols * sizeof(*Protocols));
- }
+ if (NumProtocols)
+ memcpy(reinterpret_cast<ObjCProtocolDecl**>(this + 1), Protos,
+ NumProtocols * sizeof(*Protos));
}
void ObjCInterfaceType::Destroy(ASTContext& C) {
- if (Protocols)
- C.Deallocate(Protocols);
this->~ObjCInterfaceType();
C.Deallocate(this);
}
@@ -372,22 +369,18 @@ bool Type::isObjCQualifiedInterfaceType() const {
return getAsObjCQualifiedInterfaceType() != 0;
}
-ObjCObjectPointerType::ObjCObjectPointerType(ASTContext &Ctx,
- QualType Canonical, QualType T,
+ObjCObjectPointerType::ObjCObjectPointerType(QualType Canonical, QualType T,
ObjCProtocolDecl **Protos,
unsigned NumP) :
Type(ObjCObjectPointer, Canonical, /*Dependent=*/false),
- PointeeType(T), Protocols(NULL), NumProtocols(NumP)
+ PointeeType(T), NumProtocols(NumP)
{
- if (NumProtocols) {
- Protocols = new (Ctx) ObjCProtocolDecl*[NumProtocols];
- memcpy(Protocols, Protos, NumProtocols * sizeof(*Protocols));
- }
+ if (NumProtocols)
+ memcpy(reinterpret_cast<ObjCProtocolDecl **>(this + 1), Protos,
+ NumProtocols * sizeof(*Protos));
}
void ObjCObjectPointerType::Destroy(ASTContext& C) {
- if (Protocols)
- C.Deallocate(Protocols);
this->~ObjCObjectPointerType();
C.Deallocate(this);
}
@@ -851,7 +844,8 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) {
}
void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID,
- QualType OIT, ObjCProtocolDecl **protocols,
+ QualType OIT,
+ ObjCProtocolDecl * const *protocols,
unsigned NumProtocols) {
ID.AddPointer(OIT.getAsOpaquePtr());
for (unsigned i = 0; i != NumProtocols; i++)
@@ -859,10 +853,7 @@ void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID,
}
void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) {
- if (getNumProtocols())
- Profile(ID, getPointeeType(), &Protocols[0], getNumProtocols());
- else
- Profile(ID, getPointeeType(), 0, 0);
+ Profile(ID, getPointeeType(), qual_begin(), getNumProtocols());
}
/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
@@ -1050,7 +1041,7 @@ QualType QualifierCollector::apply(const Type *T) const {
void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
const ObjCInterfaceDecl *Decl,
- ObjCProtocolDecl **protocols,
+ ObjCProtocolDecl * const *protocols,
unsigned NumProtocols) {
ID.AddPointer(Decl);
for (unsigned i = 0; i != NumProtocols; i++)
@@ -1058,10 +1049,7 @@ void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
}
void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
- if (getNumProtocols())
- Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
- else
- Profile(ID, getDecl(), 0, 0);
+ Profile(ID, getDecl(), qual_begin(), getNumProtocols());
}
Linkage Type::getLinkage() const {