Skip to content

Commit 88bc5b8

Browse files
authored
[ClangImporter] Detangle an index-based loop into two for-each loops (#27348)
No functionality change.
1 parent ccd534d commit 88bc5b8

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -870,20 +870,23 @@ namespace {
870870
unsigned typeParamCount = imported->getGenericParams()->size();
871871
auto typeArgs = type->getObjectType()->getTypeArgs();
872872
assert(typeArgs.empty() || typeArgs.size() == typeParamCount);
873-
llvm::SmallVector<Type, 2> importedTypeArgs;
874-
for (unsigned i = 0; i < typeParamCount; i++) {
875-
Type importedTypeArg;
876-
auto typeParam = imported->getGenericParams()->getParams()[i];
877-
if (!typeArgs.empty()) {
878-
auto subresult = Visit(typeArgs[i]);
879-
if (!subresult) {
873+
SmallVector<Type, 2> importedTypeArgs;
874+
importedTypeArgs.reserve(typeParamCount);
875+
if (!typeArgs.empty()) {
876+
for (auto typeArg : typeArgs) {
877+
Type importedTypeArg = Visit(typeArg).AbstractType;
878+
if (!importedTypeArg)
880879
return nullptr;
880+
importedTypeArgs.push_back(importedTypeArg);
881+
}
882+
} else {
883+
for (auto typeParam : imported->getGenericParams()->getParams()) {
884+
if (typeParam->getSuperclass() &&
885+
typeParam->getConformingProtocols().empty()) {
886+
importedTypeArgs.push_back(typeParam->getSuperclass());
887+
continue;
881888
}
882-
importedTypeArg = subresult.AbstractType;
883-
} else if (typeParam->getSuperclass() &&
884-
typeParam->getConformingProtocols().empty()) {
885-
importedTypeArg = typeParam->getSuperclass();
886-
} else {
889+
887890
SmallVector<Type, 4> memberTypes;
888891

889892
if (auto superclassType = typeParam->getSuperclass())
@@ -896,11 +899,11 @@ namespace {
896899
if (memberTypes.empty())
897900
hasExplicitAnyObject = true;
898901

899-
importedTypeArg = ProtocolCompositionType::get(
902+
Type importedTypeArg = ProtocolCompositionType::get(
900903
Impl.SwiftContext, memberTypes,
901904
hasExplicitAnyObject);
905+
importedTypeArgs.push_back(importedTypeArg);
902906
}
903-
importedTypeArgs.push_back(importedTypeArg);
904907
}
905908
assert(importedTypeArgs.size() == typeParamCount);
906909
importedType = BoundGenericClassType::get(

0 commit comments

Comments
 (0)