From 2791bd0015455fa90f42ffa2fa3faed44b0dd913 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Fri, 4 May 2012 11:31:40 -0700 Subject: [PATCH] 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. --- type.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/type.cpp b/type.cpp index 2ddbb5c7..c29ac599 100644 --- a/type.cpp +++ b/type.cpp @@ -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(a) == NULL) - a = a->GetAsNonConstType(); - if (CastType(b) == NULL) - b = b->GetAsNonConstType(); - } - else if (a->IsConstType() != b->IsConstType()) + if (ignoreConst == false && + a->IsConstType() != b->IsConstType()) return false; const AtomicType *ata = CastType(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); }