Improve efficiency of Sema::MaybeBindToTemporary by working with the
canonical type directly and adding a fast path for the common case
that the type is directly a RecordType.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149039 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index ae0c2c5..63cc9fc 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -4176,10 +4176,25 @@
if (!getLangOptions().CPlusPlus)
return Owned(E);
- QualType ET = Context.getBaseElementType(E->getType());
- const RecordType *RT = ET->getAs<RecordType>();
- if (!RT)
- return Owned(E);
+ // Search for the base element type (cf. ASTContext::getBaseElementType) with
+ // a fast path for the common case that the type is directly a RecordType.
+ const Type *T = Context.getCanonicalType(E->getType().getTypePtr());
+ const RecordType *RT = 0;
+ while (!RT) {
+ switch (T->getTypeClass()) {
+ case Type::Record:
+ RT = cast<RecordType>(T);
+ break;
+ case Type::ConstantArray:
+ case Type::IncompleteArray:
+ case Type::VariableArray:
+ case Type::DependentSizedArray:
+ T = cast<ArrayType>(T)->getElementType().getTypePtr();
+ break;
+ default:
+ return Owned(E);
+ }
+ }
// That should be enough to guarantee that this type is complete.
// If it has a trivial destructor, we can avoid the extra copy.