Skip to content

Commit ef731b3

Browse files
committed
Use small hash set in mir_inliner_callees
Use small hash set in `mir_inliner_callees` to avoid temporary allocation when possible and quadratic behaviour for large number of callees.
1 parent 6b56603 commit ef731b3

File tree

1 file changed

+4
-7
lines changed
  • compiler/rustc_mir/src/transform/inline

1 file changed

+4
-7
lines changed

compiler/rustc_mir/src/transform/inline/cycle.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2+
use rustc_data_structures::sso::SsoHashSet;
23
use rustc_data_structures::stack::ensure_sufficient_stack;
34
use rustc_hir::def_id::{DefId, LocalDefId};
45
use rustc_middle::mir::TerminatorKind;
@@ -140,7 +141,7 @@ crate fn mir_inliner_callees<'tcx>(
140141
// Functions from other crates and MIR shims
141142
_ => tcx.instance_mir(instance),
142143
};
143-
let mut calls = Vec::new();
144+
let mut calls = SsoHashSet::new();
144145
for bb_data in body.basic_blocks() {
145146
let terminator = bb_data.terminator();
146147
if let TerminatorKind::Call { func, .. } = &terminator.kind {
@@ -149,12 +150,8 @@ crate fn mir_inliner_callees<'tcx>(
149150
ty::FnDef(def_id, substs) => (*def_id, *substs),
150151
_ => continue,
151152
};
152-
// We've seen this before
153-
if calls.contains(&call) {
154-
continue;
155-
}
156-
calls.push(call);
153+
calls.insert(call);
157154
}
158155
}
159-
tcx.arena.alloc_slice(&calls)
156+
tcx.arena.alloc_from_iter(calls.iter().copied())
160157
}

0 commit comments

Comments
 (0)