Skip to content

Commit

Permalink
Auto merge of #27100 - tshepang:better-names, r=Gankro
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Jul 19, 2015
2 parents cb87ea8 + ef2f4cd commit 58fb9b5
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ impl<T> VecDeque<T> {

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

/// Returns true if and only if the buffer is at capacity
Expand Down Expand Up @@ -234,9 +234,9 @@ impl<T> VecDeque<T> {
/// assert_eq!(buf.get(1).unwrap(), &4);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self, i: usize) -> Option<&T> {
if i < self.len() {
let idx = self.wrap_add(self.tail, i);
pub fn get(&self, index: usize) -> Option<&T> {
if index < self.len() {
let idx = self.wrap_add(self.tail, index);
unsafe { Some(&*self.ptr().offset(idx as isize)) }
} else {
None
Expand All @@ -261,9 +261,9 @@ impl<T> VecDeque<T> {
/// assert_eq!(buf[1], 7);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self, i: usize) -> Option<&mut T> {
if i < self.len() {
let idx = self.wrap_add(self.tail, i);
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
if index < self.len() {
let idx = self.wrap_add(self.tail, index);
unsafe { Some(&mut *self.ptr().offset(idx as isize)) }
} else {
None
Expand Down Expand Up @@ -768,7 +768,7 @@ impl<T> VecDeque<T> {
/// assert_eq!(d.front(), Some(&2));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_front(&mut self, t: T) {
pub fn push_front(&mut self, value: T) {
if self.is_full() {
let old_cap = self.cap();
self.buf.double();
Expand All @@ -778,7 +778,7 @@ impl<T> VecDeque<T> {

self.tail = self.wrap_sub(self.tail, 1);
let tail = self.tail;
unsafe { self.buffer_write(tail, t); }
unsafe { self.buffer_write(tail, value); }
}

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

let head = self.head;
self.head = self.wrap_add(self.head, 1);
unsafe { self.buffer_write(head, t) }
unsafe { self.buffer_write(head, value) }
}

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

/// Inserts an element at position `i` within the `VecDeque`. Whichever
/// Inserts an element at `index` within the `VecDeque`. Whichever
/// end is closer to the insertion point will be moved to make room,
/// and all the affected elements will be moved to new positions.
///
/// # Panics
///
/// Panics if `i` is greater than `VecDeque`'s length
/// Panics if `index` is greater than `VecDeque`'s length
///
/// # Examples
/// ```
Expand All @@ -924,8 +924,8 @@ impl<T> VecDeque<T> {
/// buf.insert(1, 11);
/// assert_eq!(Some(&11), buf.get(1));
/// ```
pub fn insert(&mut self, i: usize, t: T) {
assert!(i <= self.len(), "index out of bounds");
pub fn insert(&mut self, index: usize, value: T) {
assert!(index <= self.len(), "index out of bounds");
if self.is_full() {
let old_cap = self.cap();
self.buf.double();
Expand Down Expand Up @@ -955,15 +955,15 @@ impl<T> VecDeque<T> {
// A - The element that should be after the insertion point
// M - Indicates element was moved

let idx = self.wrap_add(self.tail, i);
let idx = self.wrap_add(self.tail, index);

let distance_to_tail = i;
let distance_to_head = self.len() - i;
let distance_to_tail = index;
let distance_to_head = self.len() - index;

let contiguous = self.is_contiguous();

match (contiguous, distance_to_tail <= distance_to_head, idx >= self.tail) {
(true, true, _) if i == 0 => {
(true, true, _) if index == 0 => {
// push_front
//
// T
Expand Down Expand Up @@ -999,8 +999,8 @@ impl<T> VecDeque<T> {
let new_tail = self.wrap_sub(self.tail, 1);

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

self.tail = new_tail;
},
Expand All @@ -1027,7 +1027,7 @@ impl<T> VecDeque<T> {
// [o o o o o o . . . . o o I A o o]
// M M

self.copy(self.tail - 1, self.tail, i);
self.copy(self.tail - 1, self.tail, index);
self.tail -= 1;
},
(false, false, true) => unsafe {
Expand Down Expand Up @@ -1107,16 +1107,16 @@ impl<T> VecDeque<T> {
}

// tail might've been changed so we need to recalculate
let new_idx = self.wrap_add(self.tail, i);
let new_idx = self.wrap_add(self.tail, index);
unsafe {
self.buffer_write(new_idx, t);
self.buffer_write(new_idx, value);
}
}

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

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

let idx = self.wrap_add(self.tail, i);
let idx = self.wrap_add(self.tail, index);

let elem = unsafe {
Some(self.buffer_read(idx))
};

let distance_to_tail = i;
let distance_to_head = self.len() - i;
let distance_to_tail = index;
let distance_to_head = self.len() - index;

let contiguous = self.is_contiguous();

Expand All @@ -1176,7 +1176,7 @@ impl<T> VecDeque<T> {
// [. . . . o o o o o o . . . . . .]
// M M

self.copy(self.tail + 1, self.tail, i);
self.copy(self.tail + 1, self.tail, index);
self.tail += 1;
},
(true, false, _) => unsafe {
Expand All @@ -1202,7 +1202,7 @@ impl<T> VecDeque<T> {
// [o o o o o o . . . . . . o o o o]
// M M

self.copy(self.tail + 1, self.tail, i);
self.copy(self.tail + 1, self.tail, index);
self.tail = self.wrap_add(self.tail, 1);
},
(false, false, false) => unsafe {
Expand Down Expand Up @@ -1700,16 +1700,16 @@ impl<A> Index<usize> for VecDeque<A> {
type Output = A;

#[inline]
fn index(&self, i: usize) -> &A {
self.get(i).expect("Out of bounds access")
fn index(&self, index: usize) -> &A {
self.get(index).expect("Out of bounds access")
}
}

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

Expand Down

0 comments on commit 58fb9b5

Please sign in to comment.