Skip to content

Commit 74d944d

Browse files
committed
RequirementMachine: Use llvm::array_pod_sort() to sort requirements
1 parent 5689d04 commit 74d944d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,11 @@ int Requirement::compare(const Requirement &other) const {
14831483
// We should only have multiple conformance requirements.
14841484
assert(getKind() == RequirementKind::Conformance);
14851485

1486-
return TypeDecl::compare(getProtocolDecl(), other.getProtocolDecl());
1486+
int compareProtos =
1487+
TypeDecl::compare(getProtocolDecl(), other.getProtocolDecl());
1488+
assert(compareProtos != 0 && "Duplicate conformance requirements");
1489+
1490+
return compareProtos;
14871491
}
14881492

14891493
/// Compare two associated types.

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ RequirementMachine::buildRequirementSignature(ArrayRef<unsigned> rules,
193193
}
194194

195195
// Finally, sort the requirements in canonical order.
196-
std::sort(reqs.begin(), reqs.end(),
197-
[](const Requirement &lhs, const Requirement &rhs) -> bool {
198-
return lhs.compare(rhs) < 0;
199-
});
196+
llvm::array_pod_sort(reqs.begin(), reqs.end(),
197+
[](const Requirement *lhs, const Requirement *rhs) -> int {
198+
return lhs->compare(*rhs);
199+
});
200200

201201
return reqs;
202202
}

0 commit comments

Comments
 (0)