From 7306f69271bbbadb6b5dc17b266a7aaefae0cfd5 Mon Sep 17 00:00:00 2001 From: Andrew Dirksen Date: Wed, 21 Nov 2018 17:25:26 -0800 Subject: [PATCH] get_relative_to_top -> nth_from_top --- src/common/stack.rs | 20 ++++++++++---------- src/runner.rs | 2 +- src/validation/func.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/common/stack.rs b/src/common/stack.rs index 85e0901..19580cc 100644 --- a/src/common/stack.rs +++ b/src/common/stack.rs @@ -123,10 +123,10 @@ impl StackWithLimit { /// Return optional reference to item `depth` distance away from top /// - /// `bstack.get_relative_to_top(0)` gets the top of the stack + /// `bstack.nth_from_top(0)` gets the top of the stack /// - /// `bstack.get_relative_to_top(1)` gets the item just below the stack - pub(crate) fn get_relative_to_top(&self, depth: usize) -> Option<&T> { + /// `bstack.nth_from_top(1)` gets the item just below the stack + pub(crate) fn nth_from_top(&self, depth: usize) -> Option<&T> { // Be cognizant of integer underflow and overflow here. Both are possible in this situation. // len() is unsigned, so if len() == 0, subtraction is a problem // depth can legally be 2^32. On a 32 bit system, adding may overflow @@ -141,7 +141,7 @@ impl StackWithLimit { /// Return mutable reference to item `depth` distance away from top /// /// Does not check whether depth is in range. - pub(crate) fn get_relative_to_top_mut_unchecked(&mut self, depth: usize) -> &mut T { + pub(crate) fn nth_from_top_mut_unchecked(&mut self, depth: usize) -> &mut T { let offset = self.stack.len() - 1 - depth; &mut self.stack[offset] } @@ -333,16 +333,16 @@ mod test { use core::usize; #[test] - fn get_relative_to_top() { + fn nth_from_top() { let mut bstack = StackWithLimit::::with_size(StackSize::from_element_count(2)); - assert_eq!(bstack.get_relative_to_top(0), None); + assert_eq!(bstack.nth_from_top(0), None); bstack.push(1).unwrap(); bstack.push(2).unwrap(); bstack.push(3).unwrap_err(); - assert_eq!(bstack.get_relative_to_top(0), Some(&2)); - assert_eq!(bstack.get_relative_to_top(1), Some(&1)); - assert_eq!(bstack.get_relative_to_top(2), None); - assert_eq!(bstack.get_relative_to_top(3), None); + assert_eq!(bstack.nth_from_top(0), Some(&2)); + assert_eq!(bstack.nth_from_top(1), Some(&1)); + assert_eq!(bstack.nth_from_top(2), None); + assert_eq!(bstack.nth_from_top(3), None); } fn exersize(mut bstack: StackWithLimit) { diff --git a/src/runner.rs b/src/runner.rs index 21118aa..8f001a2 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -1365,7 +1365,7 @@ impl ValueStack { #[inline] fn pick_mut(&mut self, depth: usize) -> &mut RuntimeValueInternal { - self.0.get_relative_to_top_mut_unchecked(depth - 1) + self.0.nth_from_top_mut_unchecked(depth - 1) } #[inline] diff --git a/src/validation/func.rs b/src/validation/func.rs index fd1d3a3..68b2fd3 100644 --- a/src/validation/func.rs +++ b/src/validation/func.rs @@ -1487,7 +1487,7 @@ fn top_label(frame_stack: &StackWithLimit) -> &BlockFrame { fn require_label(depth: u32, frame_stack: &StackWithLimit) -> Result<&BlockFrame, Error> { frame_stack - .get_relative_to_top(depth as usize) + .nth_from_top(depth as usize) .ok_or_else(|| Error("non-empty stack expected".into())) }