Skip to content

Commit

Permalink
[std::vec] Rename .shift_opt() to .shift(), drop the old .shift() beh…
Browse files Browse the repository at this point in the history
…avior
  • Loading branch information
SimonSapin committed Jan 21, 2014
1 parent bada25e commit b5e6573
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Expand Up @@ -788,7 +788,7 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
let exe_file = make_exe_name(config, testfile);
// FIXME (#9639): This needs to handle non-utf8 paths
args.push(exe_file.as_str().unwrap().to_owned());
let prog = args.shift();
let prog = args.shift().unwrap();
return ProcArgs {prog: prog, args: args};
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/dlist.rs
Expand Up @@ -1053,7 +1053,7 @@ mod tests {
}
1 => {
m.pop_front();
if v.len() > 0 { v.shift(); }
v.shift();
}
2 | 4 => {
m.push_front(-i);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Expand Up @@ -190,7 +190,7 @@ pub fn describe_debug_flags() {

pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
let mut args = args.to_owned();
let binary = args.shift();
let binary = args.shift().unwrap();

if args.is_empty() { usage(binary); return; }

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Expand Up @@ -524,7 +524,7 @@ impl<'a> Context<'a> {
// rollback
self.is_doc_hidden = old_is_doc_hidden;
pushed.times(|| {
let (lint, lvl, src) = self.lint_stack.pop();
let (lint, lvl, src) = self.lint_stack.pop().unwrap();
self.set_level(lint, lvl, src);
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/buffered.rs
Expand Up @@ -370,7 +370,7 @@ mod test {

impl Reader for ShortReader {
fn read(&mut self, _: &mut [u8]) -> Option<uint> {
self.lengths.shift_opt()
self.lengths.shift()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/fs.rs
Expand Up @@ -519,7 +519,7 @@ pub struct Directories {

impl Iterator<Path> for Directories {
fn next(&mut self) -> Option<Path> {
match self.stack.shift_opt() {
match self.stack.shift() {
Some(path) => {
if path.is_dir() {
self.stack.push_all_move(readdir(&path));
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/str.rs
Expand Up @@ -703,7 +703,7 @@ impl<'a> Iterator<char> for Normalizations<'a> {
self.sorted = true;
}

match self.buffer.shift_opt() {
match self.buffer.shift() {
Some((c, 0)) => {
self.sorted = false;
Some(c)
Expand Down
31 changes: 8 additions & 23 deletions src/libstd/vec.rs
Expand Up @@ -1383,10 +1383,8 @@ pub trait OwnedVector<T> {
fn push_all_move(&mut self, rhs: ~[T]);
/// Remove the last element from a vector and return it, or `None` if it is empty
fn pop(&mut self) -> Option<T>;
/// 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
fn shift_opt(&mut self) -> Option<T>;
fn shift(&mut self) -> Option<T>;
/// Prepend an element to the vector
fn unshift(&mut self, x: T);

Expand Down Expand Up @@ -1578,14 +1576,11 @@ impl<T> OwnedVector<T> for ~[T] {


#[inline]
fn shift(&mut self) -> T {
self.shift_opt().expect("shift: empty vector")
}

fn shift_opt(&mut self) -> Option<T> {
fn shift(&mut self) -> Option<T> {
self.remove_opt(0)
}

#[inline]
fn unshift(&mut self, x: T) {
self.insert(0, x)
}
Expand Down Expand Up @@ -1645,7 +1640,7 @@ impl<T> OwnedVector<T> for ~[T] {
if index < ln - 1 {
self.swap(index, ln - 1);
}
self.pop()
self.pop().unwrap()
}
fn truncate(&mut self, newlen: uint) {
let oldlen = self.len();
Expand Down Expand Up @@ -3580,21 +3575,11 @@ mod tests {
#[test]
fn test_shift() {
let mut x = ~[1, 2, 3];
assert_eq!(x.shift(), 1);
assert_eq!(&x, &~[2, 3]);
assert_eq!(x.shift(), 2);
assert_eq!(x.shift(), 3);
assert_eq!(x.len(), 0);
}

#[test]
fn test_shift_opt() {
let mut x = ~[1, 2, 3];
assert_eq!(x.shift_opt(), Some(1));
assert_eq!(x.shift(), Some(1));
assert_eq!(&x, &~[2, 3]);
assert_eq!(x.shift_opt(), Some(2));
assert_eq!(x.shift_opt(), Some(3));
assert_eq!(x.shift_opt(), None);
assert_eq!(x.shift(), Some(2));
assert_eq!(x.shift(), Some(3));
assert_eq!(x.shift(), None);
assert_eq!(x.len(), 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-std.rs
Expand Up @@ -65,7 +65,7 @@ fn shift_push() {
let mut v2 = ~[];

while v1.len() > 0 {
v2.push(v1.shift());
v2.push(v1.shift().unwrap());
}
}

Expand Down

0 comments on commit b5e6573

Please sign in to comment.