]> granicus.if.org Git - clang/commitdiff
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220033 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Type.cpp

index ad8a1ed6708f4b24be66c845a2453c04f04d4cfd..726db9229f1175e401f0e13d091ba3462577d0c0 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 {