-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Correct incorrect assertion in VecDeque::wrap_copy #29545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,9 +148,9 @@ impl<T> VecDeque<T> { | |
/// Copies a contiguous block of memory len long from src to dst | ||
#[inline] | ||
unsafe fn copy(&self, dst: usize, src: usize, len: usize) { | ||
debug_assert!(dst + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len, | ||
debug_assert!(dst + len <= self.cap(), "cpy dst={} src={} len={} cap={}", dst, src, len, | ||
self.cap()); | ||
debug_assert!(src + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len, | ||
debug_assert!(src + len <= self.cap(), "cpy dst={} src={} len={} cap={}", dst, src, len, | ||
self.cap()); | ||
ptr::copy( | ||
self.ptr().offset(src as isize), | ||
|
@@ -161,9 +161,9 @@ impl<T> VecDeque<T> { | |
/// Copies a contiguous block of memory len long from src to dst | ||
#[inline] | ||
unsafe fn copy_nonoverlapping(&self, dst: usize, src: usize, len: usize) { | ||
debug_assert!(dst + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len, | ||
debug_assert!(dst + len <= self.cap(), "cno dst={} src={} len={} cap={}", dst, src, len, | ||
self.cap()); | ||
debug_assert!(src + len <= self.cap(), "dst={} src={} len={} cap={}", dst, src, len, | ||
debug_assert!(src + len <= self.cap(), "cno dst={} src={} len={} cap={}", dst, src, len, | ||
self.cap()); | ||
ptr::copy_nonoverlapping( | ||
self.ptr().offset(src as isize), | ||
|
@@ -175,9 +175,11 @@ impl<T> VecDeque<T> { | |
/// (abs(dst - src) + len) must be no larger than cap() (There must be at | ||
/// most one continuous overlapping region between src and dest). | ||
unsafe fn wrap_copy(&self, dst: usize, src: usize, len: usize) { | ||
debug_assert!( | ||
(if src <= dst { dst - src } else { src - dst }) + len <= self.cap(), | ||
"dst={} src={} len={} cap={}", dst, src, len, self.cap()); | ||
#[allow(dead_code)] | ||
fn diff(a: usize, b: usize) -> usize {if a <= b {b - a} else {a - b}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure its worth very much making this function instead of keeping it inlined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Not a big fan of this code, but it works, which is better than the old code :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's called twice, so I think it's ok. |
||
debug_assert!(cmp::min(diff(dst, src), | ||
self.cap() - diff(dst, src)) + len <= self.cap(), | ||
"wrc dst={} src={} len={} cap={}", dst, src, len, self.cap()); | ||
|
||
if src == dst || len == 0 { return } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is necessary come to think of it...