Optimize Type::isStructureOrClassType() by reusing RT->getDecl().
authorYaron Keren <yaron.keren@gmail.com>
Fri, 17 Oct 2014 11:44:44 +0000 (11:44 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Fri, 17 Oct 2014 11:44:44 +0000 (11:44 +0000)
RecordType->getDecl() which maps to TagType::getDecl() is not a simple
accessor but a loop on redecls in getInterestingTagDecl.

isStructureOrClassType() was calling getDecl() three times performing
three times the work actually required. It is optimized by calling
RT->getDecl() once and reusing the result three times.

llvm-svn: 220033

clang/lib/AST/Type.cpp

index ad8a1ed..726db92 100644 (file)
@@ -378,9 +378,10 @@ bool Type::isInterfaceType() const {
   return false;
 }
 bool Type::isStructureOrClassType() const {
-  if (const RecordType *RT = getAs<RecordType>())
-    return RT->getDecl()->isStruct() || RT->getDecl()->isClass() ||
-      RT->getDecl()->isInterface();
+  if (const RecordType *RT = getAs<RecordType>()) {
+    RecordDecl *RD = RT->getDecl();
+    return RD->isStruct() || RD->isClass() || RD->isInterface();
+  }
   return false;
 }
 bool Type::isVoidPointerType() const {