Skip to content

Commit c09f057

Browse files
committed
AST: Fast path for SubstitutionMap::lookupConformance()
1 parent 5d59a3f commit c09f057

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,20 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
318318
if (!type->isTypeParameter())
319319
return None;
320320

321+
auto genericSig = getGenericSignature();
322+
323+
// Fast path
324+
unsigned index = 0;
325+
for (auto reqt : genericSig->getRequirements()) {
326+
if (reqt.getKind() == RequirementKind::Conformance) {
327+
if (reqt.getFirstType()->isEqual(type) &&
328+
reqt.getSecondType()->isEqual(proto->getDeclaredType()))
329+
return getConformances()[index];
330+
331+
index++;
332+
}
333+
}
334+
321335
// Retrieve the starting conformance from the conformance map.
322336
auto getInitialConformance =
323337
[&](Type type, ProtocolDecl *proto) -> Optional<ProtocolConformanceRef> {
@@ -338,8 +352,6 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
338352
return None;
339353
};
340354

341-
auto genericSig = getGenericSignature();
342-
343355
// If the type doesn't conform to this protocol, the result isn't formed
344356
// from these requirements.
345357
if (!genericSig->conformsToProtocol(type, proto)) {

0 commit comments

Comments
 (0)