1
Fork 0

Rollup merge of #82482 - tmiasko:small-cycles, r=varkor

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.
This commit is contained in:
Dylan DPC 2021-02-27 02:34:32 +01:00 committed by GitHub
commit 2942cf5a1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sso::SsoHashSet;
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::mir::TerminatorKind; use rustc_middle::mir::TerminatorKind;
@ -140,7 +141,7 @@ crate fn mir_inliner_callees<'tcx>(
// Functions from other crates and MIR shims // Functions from other crates and MIR shims
_ => tcx.instance_mir(instance), _ => tcx.instance_mir(instance),
}; };
let mut calls = Vec::new(); let mut calls = SsoHashSet::new();
for bb_data in body.basic_blocks() { for bb_data in body.basic_blocks() {
let terminator = bb_data.terminator(); let terminator = bb_data.terminator();
if let TerminatorKind::Call { func, .. } = &terminator.kind { if let TerminatorKind::Call { func, .. } = &terminator.kind {
@ -149,12 +150,8 @@ crate fn mir_inliner_callees<'tcx>(
ty::FnDef(def_id, substs) => (*def_id, *substs), ty::FnDef(def_id, substs) => (*def_id, *substs),
_ => continue, _ => continue,
}; };
// We've seen this before calls.insert(call);
if calls.contains(&call) {
continue;
}
calls.push(call);
} }
} }
tcx.arena.alloc_slice(&calls) tcx.arena.alloc_from_iter(calls.iter().copied())
} }