diff options
| author | Olivier Goffart <ogoffart@woboq.com> | 2020-03-26 00:10:14 +0100 |
|---|---|---|
| committer | Olivier Goffart <ogoffart@woboq.com> | 2020-03-26 00:20:39 +0100 |
| commit | bb3e513a2cfdc01a35c5226c24b15200d635135e (patch) | |
| tree | 0eae9a6e42a93ef8c79a77f7ce1b367d1405a7ee | |
| parent | 81006f644da0963aa24aa86d1df9a69a859efcef (diff) | |
| download | rust-bb3e513a2cfdc01a35c5226c24b15200d635135e.tar.gz rust-bb3e513a2cfdc01a35c5226c24b15200d635135e.zip | |
Revert previous commit and make the optimisation in a nicer way
| -rw-r--r-- | src/librustc/ty/layout.rs | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index e8c0ec89cc4..91d39334acb 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -907,25 +907,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let count = (niche_variants.end().as_u32() - niche_variants.start().as_u32() + 1) as u128; - let mut niche_size = 0; - if let Some((field_index, niche, niche_start, niche_scalar)) = - variants[i].iter().enumerate().fold(None, |acc, (j, &field)| { - let niche = match &field.largest_niche { - Some(niche) => niche, - _ => return acc, - }; - let ns = niche.available(dl); - if ns <= niche_size { - return acc; - } - match niche.reserve(self, count) { - Some(pair) => { - niche_size = ns; - Some((j, niche, pair.0, pair.1)) - } - None => acc, - } - }) + if let Some((field_index, niche, (niche_start, niche_scalar))) = variants[i] + .iter() + .enumerate() + .filter_map(|(i, &field)| Some((i, field.largest_niche.as_ref()?))) + .max_by_key(|(_, niche)| niche.available(dl)) + .and_then(|(i, niche)| Some((i, niche, niche.reserve(self, count)?))) { let mut align = dl.aggregate_align; let st = variants |
