Skip to content

Commit

Permalink
Use FieldIdx in various things related to aggregates
Browse files Browse the repository at this point in the history
Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`.
  • Loading branch information
scottmcm committed Apr 2, 2023
1 parent e2e598f commit dc5a8c8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,15 @@ fn codegen_stmt<'tcx>(
if active_field_index.is_some() {
assert_eq!(operands.len(), 1);
}
for (i, operand) in operands.iter().enumerate() {
for (i, operand) in operands.iter_enumerated() {
let operand = codegen_operand(fx, operand);
let field_index = active_field_index.unwrap_or(i);
let to = if let mir::AggregateKind::Array(_) = **kind {
let index = fx.bcx.ins().iconst(fx.pointer_type, field_index as i64);
let array_index = i64::from(field_index.as_u32());
let index = fx.bcx.ins().iconst(fx.pointer_type, array_index);
variant_dest.place_index(fx, index)
} else {
variant_dest.place_field(fx, FieldIdx::new(field_index))
variant_dest.place_field(fx, field_index)
};
to.write_cvalue(fx, operand);
}
Expand Down

0 comments on commit dc5a8c8

Please sign in to comment.