Skip to content

Commit 979fc90

Browse files
committed
AST: Simplify ProtocolConformance::getRootNormalConformance()
1 parent 020d698 commit 979fc90

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,22 +1103,12 @@ ProtocolConformance::getRootNormalConformance() const {
11031103
const RootProtocolConformance *
11041104
ProtocolConformance::getRootConformance() const {
11051105
const ProtocolConformance *C = this;
1106-
while (true) {
1107-
switch (C->getKind()) {
1108-
case ProtocolConformanceKind::Normal:
1109-
case ProtocolConformanceKind::Self:
1110-
case ProtocolConformanceKind::Builtin:
1111-
return cast<RootProtocolConformance>(C);
1112-
case ProtocolConformanceKind::Inherited:
1113-
C = cast<InheritedProtocolConformance>(C)
1114-
->getInheritedConformance();
1115-
break;
1116-
case ProtocolConformanceKind::Specialized:
1117-
C = cast<SpecializedProtocolConformance>(C)
1118-
->getGenericConformance();
1119-
break;
1120-
}
1121-
}
1106+
if (auto *inheritedC = dyn_cast<InheritedProtocolConformance>(C))
1107+
C = inheritedC->getInheritedConformance();
1108+
if (auto *specializedC = dyn_cast<SpecializedProtocolConformance>(C))
1109+
return specializedC->getGenericConformance();
1110+
1111+
return cast<RootProtocolConformance>(C);
11221112
}
11231113

11241114
bool ProtocolConformance::isVisibleFrom(const DeclContext *dc) const {

0 commit comments

Comments
 (0)