Skip to content

Commit

Permalink
Rollup merge of #82482 - tmiasko:small-cycles, r=varkor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dylan-DPC authored Feb 27, 2021
2 parents b664e4b + ef731b3 commit 2942cf5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions compiler/rustc_mir/src/transform/inline/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sso::SsoHashSet;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::mir::TerminatorKind;
Expand Down Expand Up @@ -140,7 +141,7 @@ crate fn mir_inliner_callees<'tcx>(
// Functions from other crates and MIR shims
_ => tcx.instance_mir(instance),
};
let mut calls = Vec::new();
let mut calls = SsoHashSet::new();
for bb_data in body.basic_blocks() {
let terminator = bb_data.terminator();
if let TerminatorKind::Call { func, .. } = &terminator.kind {
Expand All @@ -149,12 +150,8 @@ crate fn mir_inliner_callees<'tcx>(
ty::FnDef(def_id, substs) => (*def_id, *substs),
_ => continue,
};
// We've seen this before
if calls.contains(&call) {
continue;
}
calls.push(call);
calls.insert(call);
}
}
tcx.arena.alloc_slice(&calls)
tcx.arena.alloc_from_iter(calls.iter().copied())
}

0 comments on commit 2942cf5

Please sign in to comment.