less misleading name for nth_from_top_mut_unchecked
This commit is contained in:
parent
21a8744e94
commit
ab67889223
|
@ -156,9 +156,14 @@ impl<T> StackWithLimit<T> {
|
||||||
/// Return mutable reference to item `depth` distance away from top
|
/// Return mutable reference to item `depth` distance away from top
|
||||||
///
|
///
|
||||||
/// Does not check whether depth is in range.
|
/// Does not check whether depth is in range.
|
||||||
pub fn nth_from_top_mut_unchecked(&mut self, depth: usize) -> &mut T {
|
///
|
||||||
let offset = self.stack.len() - 1 - depth;
|
/// # Panics
|
||||||
&mut self.stack[offset]
|
///
|
||||||
|
/// Panics if depth is out of range.
|
||||||
|
pub fn nth_from_top_mut(&mut self, depth: usize) -> &mut T {
|
||||||
|
assert!(depth + 1 <= self.stack.len());
|
||||||
|
let index = self.stack.len() - 1 - depth;
|
||||||
|
unsafe { self.stack.get_unchecked_mut(index) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Swaps two elements in the stack.
|
/// Swaps two elements in the stack.
|
||||||
|
@ -179,7 +184,7 @@ impl<T> StackWithLimit<T> {
|
||||||
/// bstack.push(1);
|
/// bstack.push(1);
|
||||||
/// bstack.push(2);
|
/// bstack.push(2);
|
||||||
/// assert_eq!(bstack.top(), Some(&2));
|
/// assert_eq!(bstack.top(), Some(&2));
|
||||||
/// stack.swap(0, 1);
|
/// bstack.swap(0, 1);
|
||||||
/// assert_eq!(bstack.top(), Some(&1));
|
/// assert_eq!(bstack.top(), Some(&1));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -202,7 +207,7 @@ impl<T> StackWithLimit<T> {
|
||||||
/// bstack.push(1);
|
/// bstack.push(1);
|
||||||
/// bstack.push(2);
|
/// bstack.push(2);
|
||||||
/// assert_eq!(bstack.top(), Some(&2));
|
/// assert_eq!(bstack.top(), Some(&2));
|
||||||
/// assert_eq!(stack.swap_remove(0), 1);
|
/// assert_eq!(bstack.swap_remove(0), 1);
|
||||||
/// assert_eq!(bstack.top(), Some(&2));
|
/// assert_eq!(bstack.top(), Some(&2));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn swap_remove(&mut self, index: usize) -> T {
|
pub fn swap_remove(&mut self, index: usize) -> T {
|
||||||
|
|
|
@ -1368,7 +1368,7 @@ impl ValueStack {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pick_mut(&mut self, depth: usize) -> &mut RuntimeValueInternal {
|
fn pick_mut(&mut self, depth: usize) -> &mut RuntimeValueInternal {
|
||||||
self.0.nth_from_top_mut_unchecked(depth - 1)
|
self.0.nth_from_top_mut(depth - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in New Issue