Skip to content

Commit 58fb9b5

Browse files
committed
Auto merge of #27100 - tshepang:better-names, r=Gankro
2 parents cb87ea8 + ef2f4cd commit 58fb9b5

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/libcollections/vec_deque.rs

+38-38
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ impl<T> VecDeque<T> {
108108

109109
/// Writes an element into the buffer, moving it.
110110
#[inline]
111-
unsafe fn buffer_write(&mut self, off: usize, t: T) {
112-
ptr::write(self.ptr().offset(off as isize), t);
111+
unsafe fn buffer_write(&mut self, off: usize, value: T) {
112+
ptr::write(self.ptr().offset(off as isize), value);
113113
}
114114

115115
/// Returns true if and only if the buffer is at capacity
@@ -234,9 +234,9 @@ impl<T> VecDeque<T> {
234234
/// assert_eq!(buf.get(1).unwrap(), &4);
235235
/// ```
236236
#[stable(feature = "rust1", since = "1.0.0")]
237-
pub fn get(&self, i: usize) -> Option<&T> {
238-
if i < self.len() {
239-
let idx = self.wrap_add(self.tail, i);
237+
pub fn get(&self, index: usize) -> Option<&T> {
238+
if index < self.len() {
239+
let idx = self.wrap_add(self.tail, index);
240240
unsafe { Some(&*self.ptr().offset(idx as isize)) }
241241
} else {
242242
None
@@ -261,9 +261,9 @@ impl<T> VecDeque<T> {
261261
/// assert_eq!(buf[1], 7);
262262
/// ```
263263
#[stable(feature = "rust1", since = "1.0.0")]
264-
pub fn get_mut(&mut self, i: usize) -> Option<&mut T> {
265-
if i < self.len() {
266-
let idx = self.wrap_add(self.tail, i);
264+
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
265+
if index < self.len() {
266+
let idx = self.wrap_add(self.tail, index);
267267
unsafe { Some(&mut *self.ptr().offset(idx as isize)) }
268268
} else {
269269
None
@@ -768,7 +768,7 @@ impl<T> VecDeque<T> {
768768
/// assert_eq!(d.front(), Some(&2));
769769
/// ```
770770
#[stable(feature = "rust1", since = "1.0.0")]
771-
pub fn push_front(&mut self, t: T) {
771+
pub fn push_front(&mut self, value: T) {
772772
if self.is_full() {
773773
let old_cap = self.cap();
774774
self.buf.double();
@@ -778,7 +778,7 @@ impl<T> VecDeque<T> {
778778

779779
self.tail = self.wrap_sub(self.tail, 1);
780780
let tail = self.tail;
781-
unsafe { self.buffer_write(tail, t); }
781+
unsafe { self.buffer_write(tail, value); }
782782
}
783783

784784
/// Appends an element to the back of a buffer
@@ -794,7 +794,7 @@ impl<T> VecDeque<T> {
794794
/// assert_eq!(3, *buf.back().unwrap());
795795
/// ```
796796
#[stable(feature = "rust1", since = "1.0.0")]
797-
pub fn push_back(&mut self, t: T) {
797+
pub fn push_back(&mut self, value: T) {
798798
if self.is_full() {
799799
let old_cap = self.cap();
800800
self.buf.double();
@@ -804,7 +804,7 @@ impl<T> VecDeque<T> {
804804

805805
let head = self.head;
806806
self.head = self.wrap_add(self.head, 1);
807-
unsafe { self.buffer_write(head, t) }
807+
unsafe { self.buffer_write(head, value) }
808808
}
809809

810810
/// Removes the last element from a buffer and returns it, or `None` if
@@ -905,13 +905,13 @@ impl<T> VecDeque<T> {
905905
self.pop_front()
906906
}
907907

908-
/// Inserts an element at position `i` within the `VecDeque`. Whichever
908+
/// Inserts an element at `index` within the `VecDeque`. Whichever
909909
/// end is closer to the insertion point will be moved to make room,
910910
/// and all the affected elements will be moved to new positions.
911911
///
912912
/// # Panics
913913
///
914-
/// Panics if `i` is greater than `VecDeque`'s length
914+
/// Panics if `index` is greater than `VecDeque`'s length
915915
///
916916
/// # Examples
917917
/// ```
@@ -924,8 +924,8 @@ impl<T> VecDeque<T> {
924924
/// buf.insert(1, 11);
925925
/// assert_eq!(Some(&11), buf.get(1));
926926
/// ```
927-
pub fn insert(&mut self, i: usize, t: T) {
928-
assert!(i <= self.len(), "index out of bounds");
927+
pub fn insert(&mut self, index: usize, value: T) {
928+
assert!(index <= self.len(), "index out of bounds");
929929
if self.is_full() {
930930
let old_cap = self.cap();
931931
self.buf.double();
@@ -955,15 +955,15 @@ impl<T> VecDeque<T> {
955955
// A - The element that should be after the insertion point
956956
// M - Indicates element was moved
957957

958-
let idx = self.wrap_add(self.tail, i);
958+
let idx = self.wrap_add(self.tail, index);
959959

960-
let distance_to_tail = i;
961-
let distance_to_head = self.len() - i;
960+
let distance_to_tail = index;
961+
let distance_to_head = self.len() - index;
962962

963963
let contiguous = self.is_contiguous();
964964

965965
match (contiguous, distance_to_tail <= distance_to_head, idx >= self.tail) {
966-
(true, true, _) if i == 0 => {
966+
(true, true, _) if index == 0 => {
967967
// push_front
968968
//
969969
// T
@@ -999,8 +999,8 @@ impl<T> VecDeque<T> {
999999
let new_tail = self.wrap_sub(self.tail, 1);
10001000

10011001
self.copy(new_tail, self.tail, 1);
1002-
// Already moved the tail, so we only copy `i - 1` elements.
1003-
self.copy(self.tail, self.tail + 1, i - 1);
1002+
// Already moved the tail, so we only copy `index - 1` elements.
1003+
self.copy(self.tail, self.tail + 1, index - 1);
10041004

10051005
self.tail = new_tail;
10061006
},
@@ -1027,7 +1027,7 @@ impl<T> VecDeque<T> {
10271027
// [o o o o o o . . . . o o I A o o]
10281028
// M M
10291029

1030-
self.copy(self.tail - 1, self.tail, i);
1030+
self.copy(self.tail - 1, self.tail, index);
10311031
self.tail -= 1;
10321032
},
10331033
(false, false, true) => unsafe {
@@ -1107,16 +1107,16 @@ impl<T> VecDeque<T> {
11071107
}
11081108

11091109
// tail might've been changed so we need to recalculate
1110-
let new_idx = self.wrap_add(self.tail, i);
1110+
let new_idx = self.wrap_add(self.tail, index);
11111111
unsafe {
1112-
self.buffer_write(new_idx, t);
1112+
self.buffer_write(new_idx, value);
11131113
}
11141114
}
11151115

1116-
/// Removes and returns the element at position `i` from the `VecDeque`.
1116+
/// Removes and returns the element at `index` from the `VecDeque`.
11171117
/// Whichever end is closer to the removal point will be moved to make
11181118
/// room, and all the affected elements will be moved to new positions.
1119-
/// Returns `None` if `i` is out of bounds.
1119+
/// Returns `None` if `index` is out of bounds.
11201120
///
11211121
/// # Examples
11221122
/// ```
@@ -1131,8 +1131,8 @@ impl<T> VecDeque<T> {
11311131
/// assert_eq!(Some(&15), buf.get(2));
11321132
/// ```
11331133
#[stable(feature = "rust1", since = "1.0.0")]
1134-
pub fn remove(&mut self, i: usize) -> Option<T> {
1135-
if self.is_empty() || self.len() <= i {
1134+
pub fn remove(&mut self, index: usize) -> Option<T> {
1135+
if self.is_empty() || self.len() <= index {
11361136
return None;
11371137
}
11381138

@@ -1154,14 +1154,14 @@ impl<T> VecDeque<T> {
11541154
// R - Indicates element that is being removed
11551155
// M - Indicates element was moved
11561156

1157-
let idx = self.wrap_add(self.tail, i);
1157+
let idx = self.wrap_add(self.tail, index);
11581158

11591159
let elem = unsafe {
11601160
Some(self.buffer_read(idx))
11611161
};
11621162

1163-
let distance_to_tail = i;
1164-
let distance_to_head = self.len() - i;
1163+
let distance_to_tail = index;
1164+
let distance_to_head = self.len() - index;
11651165

11661166
let contiguous = self.is_contiguous();
11671167

@@ -1176,7 +1176,7 @@ impl<T> VecDeque<T> {
11761176
// [. . . . o o o o o o . . . . . .]
11771177
// M M
11781178

1179-
self.copy(self.tail + 1, self.tail, i);
1179+
self.copy(self.tail + 1, self.tail, index);
11801180
self.tail += 1;
11811181
},
11821182
(true, false, _) => unsafe {
@@ -1202,7 +1202,7 @@ impl<T> VecDeque<T> {
12021202
// [o o o o o o . . . . . . o o o o]
12031203
// M M
12041204

1205-
self.copy(self.tail + 1, self.tail, i);
1205+
self.copy(self.tail + 1, self.tail, index);
12061206
self.tail = self.wrap_add(self.tail, 1);
12071207
},
12081208
(false, false, false) => unsafe {
@@ -1700,16 +1700,16 @@ impl<A> Index<usize> for VecDeque<A> {
17001700
type Output = A;
17011701

17021702
#[inline]
1703-
fn index(&self, i: usize) -> &A {
1704-
self.get(i).expect("Out of bounds access")
1703+
fn index(&self, index: usize) -> &A {
1704+
self.get(index).expect("Out of bounds access")
17051705
}
17061706
}
17071707

17081708
#[stable(feature = "rust1", since = "1.0.0")]
17091709
impl<A> IndexMut<usize> for VecDeque<A> {
17101710
#[inline]
1711-
fn index_mut(&mut self, i: usize) -> &mut A {
1712-
self.get_mut(i).expect("Out of bounds access")
1711+
fn index_mut(&mut self, index: usize) -> &mut A {
1712+
self.get_mut(index).expect("Out of bounds access")
17131713
}
17141714
}
17151715

0 commit comments

Comments
 (0)