Skip to content

Commit bb3e513

Browse files
committed
Revert previous commit and make the optimisation in a nicer way
1 parent 81006f6 commit bb3e513

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

src/librustc/ty/layout.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -907,25 +907,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
907907
let count = (niche_variants.end().as_u32()
908908
- niche_variants.start().as_u32()
909909
+ 1) as u128;
910-
let mut niche_size = 0;
911-
if let Some((field_index, niche, niche_start, niche_scalar)) =
912-
variants[i].iter().enumerate().fold(None, |acc, (j, &field)| {
913-
let niche = match &field.largest_niche {
914-
Some(niche) => niche,
915-
_ => return acc,
916-
};
917-
let ns = niche.available(dl);
918-
if ns <= niche_size {
919-
return acc;
920-
}
921-
match niche.reserve(self, count) {
922-
Some(pair) => {
923-
niche_size = ns;
924-
Some((j, niche, pair.0, pair.1))
925-
}
926-
None => acc,
927-
}
928-
})
910+
if let Some((field_index, niche, (niche_start, niche_scalar))) = variants[i]
911+
.iter()
912+
.enumerate()
913+
.filter_map(|(i, &field)| Some((i, field.largest_niche.as_ref()?)))
914+
.max_by_key(|(_, niche)| niche.available(dl))
915+
.and_then(|(i, niche)| Some((i, niche, niche.reserve(self, count)?)))
929916
{
930917
let mut align = dl.aggregate_align;
931918
let st = variants

0 commit comments

Comments
 (0)