Cache const/non-const variants of Atomic and ReferenceTypes.
More reduction of dynamic memory allocation.
This commit is contained in:
28
type.cpp
28
type.cpp
@@ -185,6 +185,7 @@ const AtomicType *AtomicType::Void =
|
||||
|
||||
AtomicType::AtomicType(BasicType bt, Variability v, bool ic)
|
||||
: Type(ATOMIC_TYPE), basicType(bt), variability(v), isConst(ic) {
|
||||
asOtherConstType = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +258,11 @@ AtomicType::GetAsConstType() const {
|
||||
if (basicType == TYPE_VOID || isConst == true)
|
||||
return this;
|
||||
|
||||
return new AtomicType(basicType, variability, true);
|
||||
if (asOtherConstType == NULL) {
|
||||
asOtherConstType = new AtomicType(basicType, variability, true);
|
||||
asOtherConstType->asOtherConstType = this;
|
||||
}
|
||||
return asOtherConstType;
|
||||
}
|
||||
|
||||
|
||||
@@ -266,7 +271,11 @@ AtomicType::GetAsNonConstType() const {
|
||||
if (basicType == TYPE_VOID || isConst == false)
|
||||
return this;
|
||||
|
||||
return new AtomicType(basicType, variability, false);
|
||||
if (asOtherConstType == NULL) {
|
||||
asOtherConstType = new AtomicType(basicType, variability, false);
|
||||
asOtherConstType->asOtherConstType = this;
|
||||
}
|
||||
return asOtherConstType;
|
||||
}
|
||||
|
||||
|
||||
@@ -2310,6 +2319,7 @@ UndefinedStructType::GetDIType(llvm::DIDescriptor scope) const {
|
||||
|
||||
ReferenceType::ReferenceType(const Type *t)
|
||||
: Type(REFERENCE_TYPE), targetType(t) {
|
||||
asOtherConstType = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -2450,7 +2460,12 @@ ReferenceType::GetAsConstType() const {
|
||||
}
|
||||
if (IsConstType())
|
||||
return this;
|
||||
return new ReferenceType(targetType->GetAsConstType());
|
||||
|
||||
if (asOtherConstType == NULL) {
|
||||
asOtherConstType = new ReferenceType(targetType->GetAsConstType());
|
||||
asOtherConstType->asOtherConstType = this;
|
||||
}
|
||||
return asOtherConstType;
|
||||
}
|
||||
|
||||
|
||||
@@ -2462,7 +2477,12 @@ ReferenceType::GetAsNonConstType() const {
|
||||
}
|
||||
if (!IsConstType())
|
||||
return this;
|
||||
return new ReferenceType(targetType->GetAsNonConstType());
|
||||
|
||||
if (asOtherConstType == NULL) {
|
||||
asOtherConstType = new ReferenceType(targetType->GetAsNonConstType());
|
||||
asOtherConstType->asOtherConstType = this;
|
||||
}
|
||||
return asOtherConstType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
type.h
3
type.h
@@ -332,6 +332,8 @@ private:
|
||||
const Variability variability;
|
||||
const bool isConst;
|
||||
AtomicType(BasicType basicType, Variability v, bool isConst);
|
||||
|
||||
mutable const AtomicType *asOtherConstType;
|
||||
};
|
||||
|
||||
|
||||
@@ -802,6 +804,7 @@ public:
|
||||
|
||||
private:
|
||||
const Type * const targetType;
|
||||
mutable const ReferenceType *asOtherConstType;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user