From b4ab8431b414ca399edc890f12f758cb19c090b8 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 26 Jan 2012 03:33:51 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaExprCXX.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index ae0c2c58c1..63cc9fc55c 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4176,10 +4176,25 @@ ExprResult Sema::MaybeBindToTemporary(Expr *E) { if (!getLangOptions().CPlusPlus) return Owned(E); - QualType ET = Context.getBaseElementType(E->getType()); - const RecordType *RT = ET->getAs(); - 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(T); + break; + case Type::ConstantArray: + case Type::IncompleteArray: + case Type::VariableArray: + case Type::DependentSizedArray: + T = cast(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. -- 2.50.1