Avoid memory copy logic for zsts

Closes #67539
This commit is contained in:
Santiago Pastorino 2019-12-27 08:56:52 -03:00
parent 8f5f8f916f
commit bd93b7718e
No known key found for this signature in database
GPG Key ID: 88C941CDA1D46432

View File

@ -845,7 +845,15 @@ pub fn copy_repeatedly(
let src_bytes = let src_bytes =
self.get_raw(src.alloc_id)?.get_bytes_with_undef_and_ptr(&tcx, src, size)?.as_ptr(); self.get_raw(src.alloc_id)?.get_bytes_with_undef_and_ptr(&tcx, src, size)?.as_ptr();
let dest_bytes = let dest_bytes =
self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?.as_mut_ptr(); self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?;
// If `dest_bytes` is empty we just optimize to not run anything for zsts.
// See #67539
if dest_bytes.is_empty() {
return Ok(());
}
let dest_bytes = dest_bytes.as_mut_ptr();
// SAFE: The above indexing would have panicked if there weren't at least `size` bytes // SAFE: The above indexing would have panicked if there weren't at least `size` bytes
// behind `src` and `dest`. Also, we use the overlapping-safe `ptr::copy` if `src` and // behind `src` and `dest`. Also, we use the overlapping-safe `ptr::copy` if `src` and