[cfe-commits] r149039 - /cfe/trunk/lib/Sema/SemaExprCXX.cpp

Peter Collingbourne peter at pcc.me.uk
Wed Jan 25 19:33:51 PST 2012


Author: pcc
Date: Wed Jan 25 21:33:51 2012
New Revision: 149039

URL: http://llvm.org/viewvc/llvm-project?rev=149039&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=149039&r1=149038&r2=149039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jan 25 21:33:51 2012
@@ -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.





More information about the cfe-commits mailing list