Skip to content

Commit a4faab4

Browse files
[NFC] Check the cache first when computing Clang types.
1 parent cd48a11 commit a4faab4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/IRGen/GenClangType.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -727,21 +727,25 @@ clang::CanQualType GenClangType::visitType(CanType type) {
727727
}
728728

729729
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+
730736
// Try to do this without making cache entries for obvious cases.
731737
if (auto nominal = dyn_cast<NominalType>(type)) {
732738
auto decl = nominal->getDecl();
733739
if (auto clangDecl = decl->getClangDecl()) {
740+
auto &ctx = IGM.getClangASTContext();
734741
if (auto clangTypeDecl = dyn_cast<clang::TypeDecl>(clangDecl)) {
735-
auto &ctx = IGM.getClangASTContext();
736742
return ctx.getCanonicalType(ctx.getTypeDeclType(clangTypeDecl))
737743
.getUnqualifiedType();
738744
} else if (auto ifaceDecl = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl)) {
739-
auto &ctx = IGM.getClangASTContext();
740745
auto clangType = ctx.getObjCInterfaceType(ifaceDecl);
741746
auto ptrTy = ctx.getObjCObjectPointerType(clangType);
742747
return ctx.getCanonicalType(ptrTy);
743748
} else if (auto protoDecl = dyn_cast<clang::ObjCProtocolDecl>(clangDecl)){
744-
auto &ctx = IGM.getClangASTContext();
745749
auto clangType = ctx.getObjCObjectType(
746750
ctx.ObjCBuiltinIdTy,
747751
const_cast<clang::ObjCProtocolDecl **>(&protoDecl),
@@ -752,12 +756,6 @@ clang::CanQualType ClangTypeConverter::convert(IRGenModule &IGM, CanType type) {
752756
}
753757
}
754758

755-
// Look in the cache.
756-
auto it = Cache.find(type);
757-
if (it != Cache.end()) {
758-
return it->second;
759-
}
760-
761759
// If that failed, convert the type, cache, and return.
762760
clang::CanQualType result = GenClangType(IGM, *this).visit(type);
763761
Cache.insert({type, result});

0 commit comments

Comments
 (0)