Skip to content

Commit 6733629

Browse files
committed
---
yaml --- r: 159196 b: refs/heads/snap-stage3 c: 4cae9ad h: refs/heads/master v: v3
1 parent a7c58c7 commit 6733629

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 40fb87d40f681f5356af42175fc7b85da387f037
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ba24e3302102eb97c253ad8d0ad08a5678428ae5
4+
refs/heads/snap-stage3: 4cae9add8c9471126aa405cacecac2623232083a
55
refs/heads/try: f58aad6dce273570fb130b4df008ef9acd5a5be2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcollections/ring_buf.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<T> RingBuf<T> {
209209
assert!(i < self.len());
210210
assert!(j < self.len());
211211
let ri = wrap_index(self.tail + i, self.cap);
212-
let rj = wrap_index(self.tail + j, self.cap);
212+
let rj = wrap_index(self.tail + j, self.cap);;
213213
unsafe {
214214
ptr::swap(self.ptr.offset(ri as int), self.ptr.offset(rj as int))
215215
}
@@ -320,6 +320,7 @@ impl<T> RingBuf<T> {
320320
);
321321
}
322322
self.head += oldcap;
323+
debug_assert!(self.head > self.tail);
323324
} else { // C
324325
unsafe {
325326
ptr::copy_nonoverlapping_memory(
@@ -329,7 +330,10 @@ impl<T> RingBuf<T> {
329330
);
330331
}
331332
self.tail = count - (oldcap - self.tail);
333+
debug_assert!(self.head < self.tail);
332334
}
335+
debug_assert!(self.head < self.cap);
336+
debug_assert!(self.tail < self.cap);
333337
}
334338
}
335339

@@ -564,7 +568,10 @@ impl<T> RingBuf<T> {
564568
/// ```
565569
#[unstable = "matches collection reform specification, waiting for dust to settle"]
566570
pub fn push_front(&mut self, t: T) {
567-
if self.is_full() { self.reserve(1) }
571+
if self.is_full() {
572+
self.reserve(1);
573+
debug_assert!(!self.is_full());
574+
}
568575

569576
self.tail = wrap_index(self.tail - 1, self.cap);
570577
let tail = self.tail;
@@ -591,7 +598,10 @@ impl<T> RingBuf<T> {
591598
/// ```
592599
#[unstable = "matches collection reform specification, waiting for dust to settle"]
593600
pub fn push_back(&mut self, t: T) {
594-
if self.is_full() { self.reserve(1) }
601+
if self.is_full() {
602+
self.reserve(1);
603+
debug_assert!(!self.is_full());
604+
}
595605

596606
let head = self.head;
597607
self.head = wrap_index(self.head + 1, self.cap);
@@ -634,7 +644,9 @@ impl<T> RingBuf<T> {
634644
#[inline]
635645
fn wrap_index(index: uint, size: uint) -> uint {
636646
// size is always a power of 2
637-
index & (size - 1)
647+
let idx = index & (size - 1);
648+
debug_assert!(idx < size);
649+
idx
638650
}
639651

640652
/// Calculate the number of elements left to be read in the buffer

0 commit comments

Comments
 (0)