From bada25e425ae30583ad343e36a034e59c66fcad6 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 23 Dec 2013 16:20:52 +0100 Subject: [std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behavior --- src/libstd/io/process.rs | 7 +++++-- src/libstd/num/strconv.rs | 2 +- src/libstd/path/posix.rs | 2 +- src/libstd/path/windows.rs | 2 +- src/libstd/repr.rs | 6 +++--- src/libstd/vec.rs | 31 ++++++------------------------- 6 files changed, 17 insertions(+), 33 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 4c8a640a849..a0c451647d3 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -161,8 +161,11 @@ impl Drop for Process { fn drop(&mut self) { // Close all I/O before exiting to ensure that the child doesn't wait // forever to print some text or something similar. - for _ in range(0, self.io.len()) { - self.io.pop(); + loop { + match self.io.pop() { + Some(_) => (), + None => break, + } } self.wait(); diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 0c41c538c6c..5c35c500e6c 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -351,7 +351,7 @@ pub fn float_to_str_bytes_common= radix / 2 { // -> need to round let mut i: int = buf.len() as int - 1; loop { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index b228dc7f1ff..dc547d702ba 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -426,7 +426,7 @@ fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<~[&'a [u8]]> { else if comp == bytes!("..") { if is_abs && comps.is_empty() { changed = true } else if comps.len() == n_up { comps.push(dot_dot_static); n_up += 1 } - else { comps.pop(); changed = true } + else { comps.pop().unwrap(); changed = true } } else { comps.push(comp) } } if changed { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 0e5b7894e74..89640add7d0 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1025,7 +1025,7 @@ fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool,Option< }; if (is_abs || has_abs_prefix) && comps.is_empty() { changed = true } else if comps.len() == n_up { comps.push(".."); n_up += 1 } - else { comps.pop(); changed = true } + else { comps.pop().unwrap(); changed = true } } else { comps.push(comp) } } if !changed && !prefix_is_verbatim(prefix) { diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 7255448bd23..8f7d01f263d 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -123,7 +123,7 @@ impl<'a> MovePtr for ReprVisitor<'a> { self.ptr_stk.push(self.ptr); } fn pop_ptr(&mut self) { - self.ptr = self.ptr_stk.pop(); + self.ptr = self.ptr_stk.pop().unwrap(); } } @@ -471,7 +471,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { n_fields: uint, name: &str) -> bool { let mut write = false; - match self.var_stk.pop() { + match self.var_stk.pop().unwrap() { SearchingFor(sought) => { if disr_val == sought { self.var_stk.push(Matched); @@ -534,7 +534,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { _sz: uint, _align: uint) -> bool { - match self.var_stk.pop() { + match self.var_stk.pop().unwrap() { SearchingFor(..) => fail!("enum value matched no variant"), _ => true } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index b3d0e9cb10a..1dfd2ea5600 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1381,10 +1381,8 @@ pub trait OwnedVector { /// assert!(a == ~[~1, ~2, ~3, ~4]); /// ``` fn push_all_move(&mut self, rhs: ~[T]); - /// Remove the last element from a vector and return it, failing if it is empty - fn pop(&mut self) -> T; /// Remove the last element from a vector and return it, or `None` if it is empty - fn pop_opt(&mut self) -> Option; + fn pop(&mut self) -> Option; /// Removes the first element from a vector and return it fn shift(&mut self) -> T; /// Removes the first element from a vector and return it, or `None` if it is empty @@ -1565,7 +1563,7 @@ impl OwnedVector for ~[T] { } } - fn pop_opt(&mut self) -> Option { + fn pop(&mut self) -> Option { match self.len() { 0 => None, ln => { @@ -1579,11 +1577,6 @@ impl OwnedVector for ~[T] { } - #[inline] - fn pop(&mut self) -> T { - self.pop_opt().expect("pop: empty vector") - } - #[inline] fn shift(&mut self) -> T { self.shift_opt().expect("shift: empty vector") @@ -3168,28 +3161,16 @@ mod tests { assert_eq!(vec.slice_to(0), &[]); } - #[test] - fn test_pop() { - // Test on-heap pop. - let mut v = ~[1, 2, 3, 4, 5]; - let e = v.pop(); - assert_eq!(v.len(), 4u); - assert_eq!(v[0], 1); - assert_eq!(v[1], 2); - assert_eq!(v[2], 3); - assert_eq!(v[3], 4); - assert_eq!(e, 5); - } #[test] - fn test_pop_opt() { + fn test_pop() { let mut v = ~[5]; - let e = v.pop_opt(); + let e = v.pop(); assert_eq!(v.len(), 0); assert_eq!(e, Some(5)); - let f = v.pop_opt(); + let f = v.pop(); assert_eq!(f, None); - let g = v.pop_opt(); + let g = v.pop(); assert_eq!(g, None); } -- cgit 1.4.1-3-g733a5