Skip to content

Commit

Permalink
Optimize copy_undef_mask() to use one pass
Browse files Browse the repository at this point in the history
This saves 0.5 seconds on the test compilation.
  • Loading branch information
wesleywiser committed Jun 30, 2018
1 parent 1ffa99d commit 8f969ed
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/librustc_mir/interpret/memory.rs
Expand Up @@ -882,25 +882,16 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
) -> EvalResult<'tcx> {
// The bits have to be saved locally before writing to dest in case src and dest overlap.
assert_eq!(size.bytes() as usize as u64, size.bytes());
let mut v = Vec::with_capacity(size.bytes() as usize);

{
let src_allocation = self.get(src.alloc_id)?;
for i in 0..size.bytes() {
let defined = src_allocation.undef_mask.get(src.offset + Size::from_bytes(i));
v.push(defined);
}
}
let undef_mask = self.get(src.alloc_id)?.undef_mask.clone();
let dest_allocation = self.get_mut(dest.alloc_id)?;

{
let dest_allocation = self.get_mut(dest.alloc_id)?;
for (i, defined) in v.into_iter().enumerate() {
dest_allocation.undef_mask.set(
dest.offset +
Size::from_bytes(i as u64),
defined,
);
}
for i in 0..size.bytes() {
let defined = undef_mask.get(src.offset + Size::from_bytes(i));
dest_allocation.undef_mask.set(
dest.offset + Size::from_bytes(i),
defined
);
}

Ok(())
Expand Down

0 comments on commit 8f969ed

Please sign in to comment.