@@ -727,21 +727,25 @@ clang::CanQualType GenClangType::visitType(CanType type) {
727
727
}
728
728
729
729
clang::CanQualType ClangTypeConverter::convert (IRGenModule &IGM, CanType type) {
730
+ // Look in the cache.
731
+ auto it = Cache.find (type);
732
+ if (it != Cache.end ()) {
733
+ return it->second ;
734
+ }
735
+
730
736
// Try to do this without making cache entries for obvious cases.
731
737
if (auto nominal = dyn_cast<NominalType>(type)) {
732
738
auto decl = nominal->getDecl ();
733
739
if (auto clangDecl = decl->getClangDecl ()) {
740
+ auto &ctx = IGM.getClangASTContext ();
734
741
if (auto clangTypeDecl = dyn_cast<clang::TypeDecl>(clangDecl)) {
735
- auto &ctx = IGM.getClangASTContext ();
736
742
return ctx.getCanonicalType (ctx.getTypeDeclType (clangTypeDecl))
737
743
.getUnqualifiedType ();
738
744
} else if (auto ifaceDecl = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl)) {
739
- auto &ctx = IGM.getClangASTContext ();
740
745
auto clangType = ctx.getObjCInterfaceType (ifaceDecl);
741
746
auto ptrTy = ctx.getObjCObjectPointerType (clangType);
742
747
return ctx.getCanonicalType (ptrTy);
743
748
} else if (auto protoDecl = dyn_cast<clang::ObjCProtocolDecl>(clangDecl)){
744
- auto &ctx = IGM.getClangASTContext ();
745
749
auto clangType = ctx.getObjCObjectType (
746
750
ctx.ObjCBuiltinIdTy ,
747
751
const_cast <clang::ObjCProtocolDecl **>(&protoDecl),
@@ -752,12 +756,6 @@ clang::CanQualType ClangTypeConverter::convert(IRGenModule &IGM, CanType type) {
752
756
}
753
757
}
754
758
755
- // Look in the cache.
756
- auto it = Cache.find (type);
757
- if (it != Cache.end ()) {
758
- return it->second ;
759
- }
760
-
761
759
// If that failed, convert the type, cache, and return.
762
760
clang::CanQualType result = GenClangType (IGM, *this ).visit (type);
763
761
Cache.insert ({type, result});
0 commit comments