@@ -115,15 +115,21 @@ impl<T> RingBuf<T> {
115
115
let size = cap. checked_mul ( & mem:: size_of :: < T > ( ) )
116
116
. expect ( "capacity overflow" ) ;
117
117
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
+
118
128
RingBuf {
119
129
tail : 0 ,
120
130
head : 0 ,
121
131
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
127
133
}
128
134
}
129
135
@@ -282,6 +288,7 @@ impl<T> RingBuf<T> {
282
288
old,
283
289
new,
284
290
mem:: min_align_of :: < T > ( ) ) as * mut T ;
291
+ if self . ptr . is_null ( ) { :: alloc:: oom ( ) }
285
292
}
286
293
}
287
294
@@ -422,9 +429,7 @@ impl<T> RingBuf<T> {
422
429
/// ```
423
430
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
424
431
pub fn clear ( & mut self ) {
425
- while !self . is_empty ( ) {
426
- self . pop_front ( ) ;
427
- }
432
+ while self . pop_front ( ) . is_some ( ) { }
428
433
self . head = 0 ;
429
434
self . tail = 0 ;
430
435
}
@@ -720,7 +725,7 @@ impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
720
725
if mem:: size_of :: < T > ( ) != 0 {
721
726
unsafe { Some ( & mut * self . ptr . offset ( tail as int ) ) }
722
727
} else {
723
- // use a none zero pointer
728
+ // use a non- zero pointer
724
729
Some ( unsafe { mem:: transmute ( 1 u) } )
725
730
}
726
731
}
0 commit comments