Skip to content

Commit 2b25c0c

Browse files
committed
Don't load the same allocation twice when reading a scalar pair from it
1 parent ba72b15 commit 2b25c0c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/librustc_mir/interpret/operand.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
242242
}
243243
};
244244

245+
let alloc = self.memory.get_raw(ptr.alloc_id)?;
246+
245247
match mplace.layout.abi {
246248
Abi::Scalar(..) => {
247-
let scalar = self.memory.get_raw(ptr.alloc_id)?.read_scalar(
248-
self,
249-
ptr,
250-
mplace.layout.size,
251-
)?;
249+
let scalar = alloc.read_scalar(self, ptr, mplace.layout.size)?;
252250
Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout }))
253251
}
254252
Abi::ScalarPair(ref a, ref b) => {
@@ -261,8 +259,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
261259
let b_offset = a_size.align_to(b.align(self).abi);
262260
assert!(b_offset.bytes() > 0); // we later use the offset to tell apart the fields
263261
let b_ptr = ptr.offset(b_offset, self)?;
264-
let a_val = self.memory.get_raw(ptr.alloc_id)?.read_scalar(self, a_ptr, a_size)?;
265-
let b_val = self.memory.get_raw(ptr.alloc_id)?.read_scalar(self, b_ptr, b_size)?;
262+
let a_val = alloc.read_scalar(self, a_ptr, a_size)?;
263+
let b_val = alloc.read_scalar(self, b_ptr, b_size)?;
266264
Ok(Some(ImmTy { imm: Immediate::ScalarPair(a_val, b_val), layout: mplace.layout }))
267265
}
268266
_ => Ok(None),

0 commit comments

Comments
 (0)