Skip to content

Commit 890881f

Browse files
committed
Auto merge of #60340 - mgeier:cap-vs-capacity, r=alexcrichton
Rename .cap() methods to .capacity() As mentioned in #60316, there are a few `.cap()` methods, which seem out-of-place because such methods are called `.capacity()` in the rest of the code. This PR renames them to `.capacity()` but leaves `RawVec::cap()` in there for backwards compatibility. I didn't try to mark the old version as "deprecated", because I guess this would cause too much noise.
2 parents eedf6ce + abe3bdf commit 890881f

File tree

6 files changed

+93
-92
lines changed

6 files changed

+93
-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(())
@@ -1887,7 +1887,7 @@ impl<T> VecDeque<T> {
18871887
let old_cap = self.cap();
18881888
self.buf.double();
18891889
unsafe {
1890-
self.handle_cap_increase(old_cap);
1890+
self.handle_capacity_increase(old_cap);
18911891
}
18921892
debug_assert!(!self.is_full());
18931893
}
@@ -2736,9 +2736,9 @@ impl<T> From<Vec<T>> for VecDeque<T> {
27362736

27372737
// We need to extend the buf if it's not a power of two, too small
27382738
// or doesn't have at least one free space
2739-
if !buf.cap().is_power_of_two() || (buf.cap() < (MINIMUM_CAPACITY + 1)) ||
2740-
(buf.cap() == len) {
2741-
let cap = cmp::max(buf.cap() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
2739+
if !buf.capacity().is_power_of_two() || (buf.capacity() < (MINIMUM_CAPACITY + 1)) ||
2740+
(buf.capacity() == len) {
2741+
let cap = cmp::max(buf.capacity() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
27422742
buf.reserve_exact(len, cap - len);
27432743
}
27442744

@@ -3153,8 +3153,8 @@ mod tests {
31533153
fn test_vec_from_vecdeque() {
31543154
use crate::vec::Vec;
31553155

3156-
fn create_vec_and_test_convert(cap: usize, offset: usize, len: usize) {
3157-
let mut vd = VecDeque::with_capacity(cap);
3156+
fn create_vec_and_test_convert(capacity: usize, offset: usize, len: usize) {
3157+
let mut vd = VecDeque::with_capacity(capacity);
31583158
for _ in 0..offset {
31593159
vd.push_back(0);
31603160
vd.pop_front();

0 commit comments

Comments
 (0)