Skip to content

Commit aa8c48a

Browse files
committed
Don't try to copy relocations if there are none
1 parent 1e3d1b6 commit aa8c48a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/librustc_mir/interpret/memory.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -700,24 +700,29 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
700700
// relocations overlapping the edges; those would not be handled correctly).
701701
let relocations = {
702702
let relocations = self.get(src.alloc_id)?.relocations(self, src, size);
703-
let mut new_relocations = Vec::with_capacity(relocations.len() * (length as usize));
704-
for i in 0..length {
705-
new_relocations.extend(
706-
relocations
707-
.iter()
708-
.map(|&(offset, reloc)| {
709-
// compute offset for current repetition
710-
let dest_offset = dest.offset + (i * size);
711-
(
712-
// shift offsets from source allocation to destination allocation
713-
offset + dest_offset - src.offset,
714-
reloc,
715-
)
716-
})
717-
);
718-
}
703+
if relocations.is_empty() {
704+
// nothing to copy, ignore even the `length` loop
705+
Vec::new()
706+
} else {
707+
let mut new_relocations = Vec::with_capacity(relocations.len() * (length as usize));
708+
for i in 0..length {
709+
new_relocations.extend(
710+
relocations
711+
.iter()
712+
.map(|&(offset, reloc)| {
713+
// compute offset for current repetition
714+
let dest_offset = dest.offset + (i * size);
715+
(
716+
// shift offsets from source allocation to destination allocation
717+
offset + dest_offset - src.offset,
718+
reloc,
719+
)
720+
})
721+
);
722+
}
719723

720-
new_relocations
724+
new_relocations
725+
}
721726
};
722727

723728
let tcx = self.tcx.tcx;

0 commit comments

Comments
 (0)