@@ -98,7 +98,7 @@ impl<T> VecDeque<T> {
98
98
// For zero sized types, we are always at maximum capacity
99
99
MAXIMUM_ZST_CAPACITY
100
100
} else {
101
- self . buf . cap ( )
101
+ self.buf.capacity ()
102
102
}
103
103
}
104
104
@@ -314,10 +314,10 @@ impl<T> VecDeque<T> {
314
314
}
315
315
316
316
/// Frobs the head and tail sections around to handle the fact that we
317
- /// just reallocated. Unsafe because it trusts old_cap .
317
+ /// just reallocated. Unsafe because it trusts old_capacity .
318
318
#[inline]
319
- unsafe fn handle_cap_increase ( & mut self , old_cap : usize ) {
320
- let new_cap = self . cap ( ) ;
319
+ unsafe fn handle_capacity_increase (&mut self, old_capacity : usize) {
320
+ let new_capacity = self.cap();
321
321
322
322
// Move the shortest contiguous section of the ring buffer
323
323
// T H
@@ -336,15 +336,15 @@ impl<T> VecDeque<T> {
336
336
if self.tail <= self.head {
337
337
// A
338
338
// Nop
339
- } else if self . head < old_cap - self . tail {
339
+ } else if self.head < old_capacity - self.tail {
340
340
// B
341
- self . copy_nonoverlapping ( old_cap , 0 , self . head ) ;
342
- self . head += old_cap ;
341
+ self.copy_nonoverlapping(old_capacity , 0, self.head);
342
+ self.head += old_capacity ;
343
343
debug_assert!(self.head > self.tail);
344
344
} else {
345
345
// C
346
- let new_tail = new_cap - ( old_cap - self . tail ) ;
347
- self . copy_nonoverlapping ( new_tail, self . tail , old_cap - self . tail ) ;
346
+ let new_tail = new_capacity - (old_capacity - self.tail);
347
+ self.copy_nonoverlapping(new_tail, self.tail, old_capacity - self.tail);
348
348
self.tail = new_tail;
349
349
debug_assert!(self.head < self.tail);
350
350
}
@@ -551,7 +551,7 @@ impl<T> VecDeque<T> {
551
551
if new_cap > old_cap {
552
552
self.buf.reserve_exact(used_cap, new_cap - used_cap);
553
553
unsafe {
554
- self . handle_cap_increase ( old_cap) ;
554
+ self.handle_capacity_increase (old_cap);
555
555
}
556
556
}
557
557
}
@@ -641,7 +641,7 @@ impl<T> VecDeque<T> {
641
641
if new_cap > old_cap {
642
642
self.buf.try_reserve_exact(used_cap, new_cap - used_cap)?;
643
643
unsafe {
644
- self . handle_cap_increase ( old_cap) ;
644
+ self.handle_capacity_increase (old_cap);
645
645
}
646
646
}
647
647
Ok(())
@@ -1887,7 +1887,7 @@ impl<T> VecDeque<T> {
1887
1887
let old_cap = self.cap();
1888
1888
self.buf.double();
1889
1889
unsafe {
1890
- self . handle_cap_increase ( old_cap) ;
1890
+ self.handle_capacity_increase (old_cap);
1891
1891
}
1892
1892
debug_assert!(!self.is_full());
1893
1893
}
@@ -2723,9 +2723,9 @@ impl<T> From<Vec<T>> for VecDeque<T> {
2723
2723
2724
2724
// We need to extend the buf if it's not a power of two, too small
2725
2725
// or doesn't have at least one free space
2726
- if !buf. cap ( ) . is_power_of_two ( ) || ( buf. cap ( ) < ( MINIMUM_CAPACITY + 1 ) ) ||
2727
- ( buf. cap ( ) == len) {
2728
- let cap = cmp:: max ( buf. cap ( ) + 1 , MINIMUM_CAPACITY + 1 ) . next_power_of_two ( ) ;
2726
+ if !buf.capacity ().is_power_of_two() || (buf.capacity () < (MINIMUM_CAPACITY + 1)) ||
2727
+ (buf.capacity () == len) {
2728
+ let cap = cmp::max(buf.capacity () + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
2729
2729
buf.reserve_exact(len, cap - len);
2730
2730
}
2731
2731
@@ -3137,8 +3137,8 @@ mod tests {
3137
3137
fn test_vec_from_vecdeque() {
3138
3138
use crate::vec::Vec;
3139
3139
3140
- fn create_vec_and_test_convert ( cap : usize , offset : usize , len : usize ) {
3141
- let mut vd = VecDeque :: with_capacity ( cap ) ;
3140
+ fn create_vec_and_test_convert(capacity : usize, offset: usize, len: usize) {
3141
+ let mut vd = VecDeque::with_capacity(capacity );
3142
3142
for _ in 0..offset {
3143
3143
vd.push_back(0);
3144
3144
vd.pop_front();
0 commit comments