Skip to content

Commit a7c58c7

Browse files
committed
---
yaml --- r: 159195 b: refs/heads/snap-stage3 c: ba24e33 h: refs/heads/master i: 159193: 712f8ea 159191: 14beeff v: v3
1 parent 1014a81 commit a7c58c7

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
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: 7a666df5fa6295e82d4350a6eb105c0370aca7a1
4+
refs/heads/snap-stage3: ba24e3302102eb97c253ad8d0ad08a5678428ae5
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: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,21 @@ impl<T> RingBuf<T> {
115115
let size = cap.checked_mul(&mem::size_of::<T>())
116116
.expect("capacity overflow");
117117

118+
let ptr = if mem::size_of::<T>() != 0 {
119+
unsafe {
120+
let ptr = heap::allocate(size, mem::min_align_of::<T>()) as *mut T;;
121+
if ptr.is_null() { ::alloc::oom() }
122+
ptr
123+
}
124+
} else {
125+
heap::EMPTY as *mut T
126+
};
127+
118128
RingBuf {
119129
tail: 0,
120130
head: 0,
121131
cap: cap,
122-
ptr: if mem::size_of::<T>() != 0 {
123-
unsafe { heap::allocate(size, mem::min_align_of::<T>()) as *mut T }
124-
} else {
125-
heap::EMPTY as *mut T
126-
}
132+
ptr: ptr
127133
}
128134
}
129135

@@ -282,6 +288,7 @@ impl<T> RingBuf<T> {
282288
old,
283289
new,
284290
mem::min_align_of::<T>()) as *mut T;
291+
if self.ptr.is_null() { ::alloc::oom() }
285292
}
286293
}
287294

@@ -422,9 +429,7 @@ impl<T> RingBuf<T> {
422429
/// ```
423430
#[unstable = "matches collection reform specification, waiting for dust to settle"]
424431
pub fn clear(&mut self) {
425-
while !self.is_empty() {
426-
self.pop_front();
427-
}
432+
while self.pop_front().is_some() {}
428433
self.head = 0;
429434
self.tail = 0;
430435
}
@@ -720,7 +725,7 @@ impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
720725
if mem::size_of::<T>() != 0 {
721726
unsafe { Some(&mut *self.ptr.offset(tail as int)) }
722727
} else {
723-
// use a none zero pointer
728+
// use a non-zero pointer
724729
Some(unsafe { mem::transmute(1u) })
725730
}
726731
}

0 commit comments

Comments
 (0)