interpret/visitor: make memory order iteration slightly more efficient
This commit is contained in:
parent
6cf068db56
commit
de34a91350
2 changed files with 15 additions and 17 deletions
|
@ -25,14 +25,15 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
|
|||
}
|
||||
|
||||
/// This function provides the chance to reorder the order in which fields are visited for
|
||||
/// `FieldsShape::Aggregate`: The order of fields will be
|
||||
/// `(0..num_fields).map(aggregate_field_order)`.
|
||||
/// `FieldsShape::Aggregate`.
|
||||
///
|
||||
/// The default means we iterate in source declaration order; alternative this can do an inverse
|
||||
/// lookup in `memory_index` to use memory field order instead.
|
||||
/// The default means we iterate in source declaration order; alternatively this can do some
|
||||
/// work with `memory_index` to iterate in memory order.
|
||||
#[inline(always)]
|
||||
fn aggregate_field_order(_memory_index: &IndexVec<FieldIdx, u32>, idx: usize) -> usize {
|
||||
idx
|
||||
fn aggregate_field_iter(
|
||||
memory_index: &IndexVec<FieldIdx, u32>,
|
||||
) -> impl Iterator<Item = FieldIdx> + 'static {
|
||||
memory_index.indices()
|
||||
}
|
||||
|
||||
// Recursive actions, ready to be overloaded.
|
||||
|
@ -172,9 +173,9 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
|
|||
&FieldsShape::Union(fields) => {
|
||||
self.visit_union(v, fields)?;
|
||||
}
|
||||
FieldsShape::Arbitrary { offsets, memory_index } => {
|
||||
for idx in 0..offsets.len() {
|
||||
let idx = Self::aggregate_field_order(memory_index, idx);
|
||||
FieldsShape::Arbitrary { memory_index, .. } => {
|
||||
for idx in Self::aggregate_field_iter(memory_index) {
|
||||
let idx = idx.as_usize();
|
||||
let field = self.ecx().project_field(v, idx)?;
|
||||
self.visit_field(v, idx, &field)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue