Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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)]
Copy link
Contributor Author

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...

fn diff(a: usize, b: usize) -> usize {if a <= b {b - a} else {a - b}}
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The 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 }

Expand Down