Skip to content

Commit 3508dfb

Browse files
committed
[Constraint system] Use hash table lookup appropriately.
It’s pointlessly inefficient to do an O(n) scan through a hash table to match keys!
1 parent f5b9517 commit 3508dfb

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7538,13 +7538,7 @@ ProtocolConformanceRef Solution::resolveConformance(
75387538
}
75397539

75407540
Type Solution::getType(const Expr *expr) const {
7541-
auto result = llvm::find_if(
7542-
nodeTypes, [&](const std::pair<TypedNode, Type> &node) -> bool {
7543-
if (auto *e = node.first.dyn_cast<const Expr *>())
7544-
return expr == e;
7545-
return false;
7546-
});
7547-
7541+
auto result = nodeTypes.find(expr);
75487542
if (result != nodeTypes.end())
75497543
return result->second;
75507544

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ class ConstraintSystem {
14841484
/// nodes themselves. This allows us to typecheck and
14851485
/// run through various diagnostics passes without actually mutating
14861486
/// the types on the nodes.
1487-
llvm::DenseMap<TypedNode, Type> NodeTypes;
1487+
llvm::MapVector<TypedNode, Type> NodeTypes;
14881488
llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned>, TypeBase *>
14891489
KeyPathComponentTypes;
14901490

0 commit comments

Comments
 (0)