Skip to content

Commit 0967d28

Browse files
committed
Rename .cap() methods to .capacity()
... but leave the old names in there for backwards compatibility.
1 parent c751c7a commit 0967d28

File tree

6 files changed

+99
-92
lines changed

6 files changed

+99
-92
lines changed

src/liballoc/collections/vec_deque.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<T> VecDeque<T> {
9898
// For zero sized types, we are always at maximum capacity
9999
MAXIMUM_ZST_CAPACITY
100100
} else {
101-
self.buf.cap()
101+
self.buf.capacity()
102102
}
103103
}
104104

@@ -314,10 +314,10 @@ impl<T> VecDeque<T> {
314314
}
315315

316316
/// 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.
318318
#[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();
321321

322322
// Move the shortest contiguous section of the ring buffer
323323
// T H
@@ -336,15 +336,15 @@ impl<T> VecDeque<T> {
336336
if self.tail <= self.head {
337337
// A
338338
// Nop
339-
} else if self.head < old_cap - self.tail {
339+
} else if self.head < old_capacity - self.tail {
340340
// 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;
343343
debug_assert!(self.head > self.tail);
344344
} else {
345345
// 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);
348348
self.tail = new_tail;
349349
debug_assert!(self.head < self.tail);
350350
}
@@ -551,7 +551,7 @@ impl<T> VecDeque<T> {
551551
if new_cap > old_cap {
552552
self.buf.reserve_exact(used_cap, new_cap - used_cap);
553553
unsafe {
554-
self.handle_cap_increase(old_cap);
554+
self.handle_capacity_increase(old_cap);
555555
}
556556
}
557557
}
@@ -641,7 +641,7 @@ impl<T> VecDeque<T> {
641641
if new_cap > old_cap {
642642
self.buf.try_reserve_exact(used_cap, new_cap - used_cap)?;
643643
unsafe {
644-
self.handle_cap_increase(old_cap);
644+
self.handle_capacity_increase(old_cap);
645645
}
646646
}
647647
Ok(())
@@ -1873,7 +1873,7 @@ impl<T> VecDeque<T> {
18731873
let old_cap = self.cap();
18741874
self.buf.double();
18751875
unsafe {
1876-
self.handle_cap_increase(old_cap);
1876+
self.handle_capacity_increase(old_cap);
18771877
}
18781878
debug_assert!(!self.is_full());
18791879
}
@@ -2708,9 +2708,9 @@ impl<T> From<Vec<T>> for VecDeque<T> {
27082708

27092709
// We need to extend the buf if it's not a power of two, too small
27102710
// or doesn't have at least one free space
2711-
if !buf.cap().is_power_of_two() || (buf.cap() < (MINIMUM_CAPACITY + 1)) ||
2712-
(buf.cap() == len) {
2713-
let cap = cmp::max(buf.cap() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
2711+
if !buf.capacity().is_power_of_two() || (buf.capacity() < (MINIMUM_CAPACITY + 1)) ||
2712+
(buf.capacity() == len) {
2713+
let cap = cmp::max(buf.capacity() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
27142714
buf.reserve_exact(len, cap - len);
27152715
}
27162716

@@ -3096,8 +3096,8 @@ mod tests {
30963096
fn test_vec_from_vecdeque() {
30973097
use crate::vec::Vec;
30983098

3099-
fn create_vec_and_test_convert(cap: usize, offset: usize, len: usize) {
3100-
let mut vd = VecDeque::with_capacity(cap);
3099+
fn create_vec_and_test_convert(capacity: usize, offset: usize, len: usize) {
3100+
let mut vd = VecDeque::with_capacity(capacity);
31013101
for _ in 0..offset {
31023102
vd.push_back(0);
31033103
vd.pop_front();

0 commit comments

Comments
 (0)