Skip to content

Commit 1e057a2

Browse files
committed
Auto merge of rust-lang#50631 - pietroalbini:beta-backports, r=alexcrichton
[beta] Process backports * rust-lang#50575: std: Avoid `ptr::copy` if unnecessary in `vec::Drain` r? @alexcrichton
2 parents 03fb2f4 + dfc9570 commit 1e057a2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/liballoc/vec.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2533,9 +2533,11 @@ impl<'a, T> Drop for Drain<'a, T> {
25332533
// memmove back untouched tail, update to new length
25342534
let start = source_vec.len();
25352535
let tail = self.tail_start;
2536-
let src = source_vec.as_ptr().offset(tail as isize);
2537-
let dst = source_vec.as_mut_ptr().offset(start as isize);
2538-
ptr::copy(src, dst, self.tail_len);
2536+
if tail != start {
2537+
let src = source_vec.as_ptr().offset(tail as isize);
2538+
let dst = source_vec.as_mut_ptr().offset(start as isize);
2539+
ptr::copy(src, dst, self.tail_len);
2540+
}
25392541
source_vec.set_len(start + self.tail_len);
25402542
}
25412543
}

0 commit comments

Comments
 (0)