Improve performance of lCheckTypeEquality()

We don't need to explicitly create the non-const Types to do type
comparison when ignoring const-ness in the check.

We can also save some unnecessary dynamic memory allocation by
keeping strings returned from GetStructName() as references to strings.

This gives another 10% on front-end perf on that big program.
This commit is contained in:
Matt Pharr
2012-05-04 11:31:40 -07:00
parent 7cf66eb61f
commit 2791bd0015

View File

@@ -3106,13 +3106,8 @@ lCheckTypeEquality(const Type *a, const Type *b, bool ignoreConst) {
if (a == NULL || b == NULL)
return false;
if (ignoreConst == true) {
if (CastType<FunctionType>(a) == NULL)
a = a->GetAsNonConstType();
if (CastType<FunctionType>(b) == NULL)
b = b->GetAsNonConstType();
}
else if (a->IsConstType() != b->IsConstType())
if (ignoreConst == false &&
a->IsConstType() != b->IsConstType())
return false;
const AtomicType *ata = CastType<AtomicType>(a);
@@ -3156,8 +3151,10 @@ lCheckTypeEquality(const Type *a, const Type *b, bool ignoreConst) {
if (a->GetVariability() != b->GetVariability())
return false;
std::string namea = sta ? sta->GetStructName() : usta->GetStructName();
std::string nameb = stb ? stb->GetStructName() : ustb->GetStructName();
const std::string &namea = sta ? sta->GetStructName() :
usta->GetStructName();
const std::string &nameb = stb ? stb->GetStructName() :
ustb->GetStructName();
return (namea == nameb);
}