diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2012-01-26 03:33:51 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2012-01-26 03:33:51 +0000 |
commit | b4ab8431b414ca399edc890f12f758cb19c090b8 (patch) | |
tree | 030a5978e2dde4df751c392ba97cde38d3b4f2a4 /lib/Sema/SemaExprCXX.cpp | |
parent | 95b68f94d28a4b94f4c3fb029b9f1690e1bb728b (diff) |
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
Diffstat (limited to 'lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 23 |
1 files 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<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. |