diff options
| author | bors <bors@rust-lang.org> | 2020-10-07 23:44:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-07 23:44:57 +0000 |
| commit | e055f87cdfcac1f4da6c518a547dee459de0aa26 (patch) | |
| tree | bb27e222fe5e2835df345328c6c1797d4e0cbf24 /compiler | |
| parent | 91a79fb29ac78d057d04dbe86be13d5dcc64309a (diff) | |
| parent | e231c47aa608b15aa427bc7a8859d87a022c1cfd (diff) | |
| download | rust-e055f87cdfcac1f4da6c518a547dee459de0aa26.tar.gz rust-e055f87cdfcac1f4da6c518a547dee459de0aa26.zip | |
Auto merge of #77597 - simonvandel:uninhabited-hashset, r=jonas-schievink
perf: UninhabitedEnumBranching avoid n^2 Avoid n² complexity. This showed up in a profile for match-stress-enum that has 8192 variants I have only profiled locally against `match-stress-enum`, so we should have it perf tested to make sure it does not regress other crates.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs b/compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs index a6bfa0c7409..87906e83ed5 100644 --- a/compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs +++ b/compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs @@ -1,6 +1,7 @@ //! A pass that eliminates branches on uninhabited enum variants. use crate::transform::MirPass; +use rustc_data_structures::stable_set::FxHashSet; use rustc_middle::mir::{ BasicBlock, BasicBlockData, Body, Local, Operand, Rvalue, StatementKind, TerminatorKind, }; @@ -52,9 +53,13 @@ fn variant_discriminants<'tcx>( layout: &TyAndLayout<'tcx>, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>, -) -> Vec<u128> { +) -> FxHashSet<u128> { match &layout.variants { - Variants::Single { index } => vec![index.as_u32() as u128], + Variants::Single { index } => { + let mut res = FxHashSet::default(); + res.insert(index.as_u32() as u128); + res + } Variants::Multiple { variants, .. } => variants .iter_enumerated() .filter_map(|(idx, layout)| { |
