diff options
| author | bors <bors@rust-lang.org> | 2014-02-10 14:56:47 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-10 14:56:47 -0800 |
| commit | 38ed4674e8054ee854871303401bffed7c05b01b (patch) | |
| tree | 59745ee9aa34079821e8afa2274a4bc83e98254d /src/libstd | |
| parent | cf9164f94c6a7e3717f67b1fb74a7662639835f0 (diff) | |
| parent | e9ff91e9beb6c92d9662242c1090c507b1611c59 (diff) | |
| download | rust-38ed4674e8054ee854871303401bffed7c05b01b.tar.gz rust-38ed4674e8054ee854871303401bffed7c05b01b.zip | |
auto merge of #11956 : edwardw/rust/issue-7556, r=cmr
Closes #7556. Also move ``std::util::Void`` to ``std::any::Void``. It makes more sense to me.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/any.rs | 4 | ||||
| -rw-r--r-- | src/libstd/comm/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/fmt/mod.rs | 10 | ||||
| -rw-r--r-- | src/libstd/hashmap.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/fs.rs | 1 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 8 | ||||
| -rw-r--r-- | src/libstd/iter.rs | 4 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/local_data.rs | 4 | ||||
| -rw-r--r-- | src/libstd/logging.rs | 6 | ||||
| -rw-r--r-- | src/libstd/mem.rs | 120 | ||||
| -rw-r--r-- | src/libstd/option.rs | 4 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 5 | ||||
| -rw-r--r-- | src/libstd/ptr.rs | 3 | ||||
| -rw-r--r-- | src/libstd/repr.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/args.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/at_exit_imp.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/unwind.rs | 4 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 7 | ||||
| -rw-r--r-- | src/libstd/util.rs | 160 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 19 |
21 files changed, 163 insertions, 210 deletions
diff --git a/src/libstd/any.rs b/src/libstd/any.rs index 4433bd9096f..24da59341cc 100644 --- a/src/libstd/any.rs +++ b/src/libstd/any.rs @@ -26,7 +26,9 @@ use result::{Result, Ok, Err}; use to_str::ToStr; use unstable::intrinsics::TypeId; use unstable::intrinsics; -use util::Void; + +/// A type with no inhabitants +pub enum Void { } /////////////////////////////////////////////////////////////////////////////// // Any trait diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index 366c268fae2..34bf83ac491 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -257,7 +257,6 @@ macro_rules! test ( use super::*; use super::super::*; use task; - use util; fn f() $b diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index d2e9fe040f7..c8b5d3b2d5a 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -477,6 +477,7 @@ will look like `"\\{"`. */ +use any; use cast; use char::Char; use container::Container; @@ -489,7 +490,6 @@ use repr; use result::{Ok, Err}; use str::StrSlice; use str; -use util; use vec::ImmutableVector; use vec; @@ -524,8 +524,8 @@ pub struct Formatter<'a> { /// compile time it is ensured that the function and the value have the correct /// types, and then this struct is used to canonicalize arguments to one type. pub struct Argument<'a> { - priv formatter: extern "Rust" fn(&util::Void, &mut Formatter) -> Result, - priv value: &'a util::Void, + priv formatter: extern "Rust" fn(&any::Void, &mut Formatter) -> Result, + priv value: &'a any::Void, } impl<'a> Arguments<'a> { @@ -794,11 +794,11 @@ impl<'a> Formatter<'a> { rt::CountImplied => { None } rt::CountIsParam(i) => { let v = self.args[i].value; - unsafe { Some(*(v as *util::Void as *uint)) } + unsafe { Some(*(v as *any::Void as *uint)) } } rt::CountIsNextParam => { let v = self.curarg.next().unwrap().value; - unsafe { Some(*(v as *util::Void as *uint)) } + unsafe { Some(*(v as *any::Void as *uint)) } } } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 7669467d4bb..953cc66a2cb 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -60,11 +60,11 @@ use hash::Hash; use iter; use iter::{Iterator, FromIterator, Extendable}; use iter::{FilterMap, Chain, Repeat, Zip}; +use mem::replace; use num; use option::{None, Option, Some}; use rand::Rng; use rand; -use util::replace; use vec::{ImmutableVector, MutableVector, OwnedVector, Items, MutItems}; use vec_ng; use vec_ng::Vec; diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index ef1b1a56ec0..cd6c6763f66 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -659,7 +659,6 @@ mod test { use io::fs::{File, rmdir, mkdir, readdir, rmdir_recursive, mkdir_recursive, copy, unlink, stat, symlink, link, readlink, chmod, lstat, change_file_times}; - use util; use path::Path; use io; use ops::Drop; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 937ad0783e9..2cc0c67ff6a 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -32,6 +32,7 @@ use fmt; use io::{Reader, Writer, IoResult, IoError, OtherIoError, standard_error, EndOfFile, LineBufferedWriter}; use libc; +use mem::replace; use option::{Option, Some, None}; use prelude::drop; use result::{Ok, Err}; @@ -39,7 +40,6 @@ use rt::local::Local; use rt::rtio::{DontClose, IoFactory, LocalIo, RtioFileStream, RtioTTY}; use rt::task::Task; use str::StrSlice; -use util; use vec::ImmutableVector; // And so begins the tale of acquiring a uv handle to a stdio stream on all @@ -132,7 +132,7 @@ fn reset_helper(w: ~Writer, /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stdout stream. pub fn set_stdout(stdout: ~Writer) -> Option<~Writer> { - reset_helper(stdout, |t, w| util::replace(&mut t.stdout, Some(w))) + reset_helper(stdout, |t, w| replace(&mut t.stdout, Some(w))) } /// Resets the task-local stderr handle to the specified writer @@ -144,7 +144,7 @@ pub fn set_stdout(stdout: ~Writer) -> Option<~Writer> { /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stderr stream. pub fn set_stderr(stderr: ~Writer) -> Option<~Writer> { - reset_helper(stderr, |t, w| util::replace(&mut t.stderr, Some(w))) + reset_helper(stderr, |t, w| replace(&mut t.stderr, Some(w))) } // Helper to access the local task's stdout handle @@ -183,7 +183,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) { // temporarily take the task, swap the handles, put the task in TLS, // and only then drop the previous handle. let mut t = Local::borrow(None::<Task>); - let prev = util::replace(&mut t.get().stdout, my_stdout); + let prev = replace(&mut t.get().stdout, my_stdout); drop(t); drop(prev); ret diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index 69260e4575d..0b1c084a546 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -71,7 +71,7 @@ use ops::{Add, Mul, Sub}; use cmp::{Eq, Ord}; use clone::Clone; use uint; -use util; +use mem; /// Conversion from an `Iterator` pub trait FromIterator<A> { @@ -701,7 +701,7 @@ impl<'a, A, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T fn reverse_(&mut self) { loop { match (self.next(), self.next_back()) { - (Some(x), Some(y)) => util::swap(x, y), + (Some(x), Some(y)) => mem::swap(x, y), _ => break } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7b574d68e78..e0666ef4179 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -178,7 +178,6 @@ pub mod cast; pub mod fmt; pub mod cleanup; pub mod logging; -pub mod util; pub mod mem; diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 8e6643f0413..043da46ba5e 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -45,7 +45,7 @@ use option::{None, Option, Some}; use vec::{ImmutableVector, MutableVector, OwnedVector}; use iter::{Iterator}; use rt::task::{Task, LocalStorage}; -use util::replace; +use mem::replace; /** * Indexes a task-local data slot. This pointer is used for comparison to @@ -149,7 +149,7 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> { fail!("TLS value cannot be removed because it is currently \ borrowed as {}", loan.describe()); } - // Move the data out of the `entry` slot via util::replace. + // Move the data out of the `entry` slot via prelude::replace. // This is guaranteed to succeed because we already matched // on `Some` above. let data = match replace(entry, None) { diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs index c5e66ffc7be..165a83aa975 100644 --- a/src/libstd/logging.rs +++ b/src/libstd/logging.rs @@ -99,13 +99,13 @@ use fmt; use io::LineBufferedWriter; use io; use io::Writer; +use mem::replace; use ops::Drop; use option::{Some, None, Option}; use prelude::drop; use result::{Ok, Err}; use rt::local::Local; use rt::task::Task; -use util; /// Debug log level pub static DEBUG: u32 = 4; @@ -173,7 +173,7 @@ pub fn log(level: u32, args: &fmt::Arguments) { logger.get_mut_ref().log(level, args); let mut task = Local::borrow(None::<Task>); - let prev = util::replace(&mut task.get().logger, logger); + let prev = replace(&mut task.get().logger, logger); drop(task); drop(prev); } @@ -182,5 +182,5 @@ pub fn log(level: u32, args: &fmt::Arguments) { /// logger. pub fn set_logger(logger: ~Logger) -> Option<~Logger> { let mut task = Local::borrow(None::<Task>); - util::replace(&mut task.get().logger, Some(logger)) + replace(&mut task.get().logger, Some(logger)) } diff --git a/src/libstd/mem.rs b/src/libstd/mem.rs index ccedd34a0d1..09d2db329ca 100644 --- a/src/libstd/mem.rs +++ b/src/libstd/mem.rs @@ -15,6 +15,8 @@ #[allow(missing_doc)]; // FIXME +use cast; +use ptr; use unstable::intrinsics; use unstable::intrinsics::{bswap16, bswap32, bswap64}; @@ -126,9 +128,45 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) { #[cfg(target_endian = "big")] #[inline] pub fn from_be64(x: i64) -> i64 { x } +/** + * Swap the values at two mutable locations of the same type, without + * deinitialising or copying either one. + */ +#[inline] +pub fn swap<T>(x: &mut T, y: &mut T) { + unsafe { + // Give ourselves some scratch space to work with + let mut t: T = uninit(); + + // Perform the swap, `&mut` pointers never alias + ptr::copy_nonoverlapping_memory(&mut t, &*x, 1); + ptr::copy_nonoverlapping_memory(x, &*y, 1); + ptr::copy_nonoverlapping_memory(y, &t, 1); + + // y and t now point to the same thing, but we need to completely forget `tmp` + // because it's no longer relevant. + cast::forget(t); + } +} + +/** + * Replace the value at a mutable location with a new one, returning the old + * value, without deinitialising or copying either one. + */ +#[inline] +pub fn replace<T>(dest: &mut T, mut src: T) -> T { + swap(dest, &mut src); + src +} + +/// Disposes of a value. +#[inline] +pub fn drop<T>(_x: T) { } + #[cfg(test)] mod tests { use mem::*; + use option::{Some,None}; #[test] fn size_of_basic() { @@ -207,4 +245,86 @@ mod tests { assert_eq!(pref_align_of_val(&1u16), 2u); assert_eq!(pref_align_of_val(&1u32), 4u); } + + #[test] + fn test_swap() { + let mut x = 31337; + let mut y = 42; + swap(&mut x, &mut y); + assert_eq!(x, 42); + assert_eq!(y, 31337); + } + + #[test] + fn test_replace() { + let mut x = Some(~"test"); + let y = replace(&mut x, None); + assert!(x.is_none()); + assert!(y.is_some()); + } +} + +/// Completely miscellaneous language-construct benchmarks. +#[cfg(test)] +mod bench { + + use extra::test::BenchHarness; + use option::{Some,None}; + + // Static/dynamic method dispatch + + struct Struct { + field: int + } + + trait Trait { + fn method(&self) -> int; + } + + impl Trait for Struct { + fn method(&self) -> int { + self.field + } + } + + #[bench] + fn trait_vtable_method_call(bh: &mut BenchHarness) { + let s = Struct { field: 10 }; + let t = &s as &Trait; + bh.iter(|| { + t.method(); + }); + } + + #[bench] + fn trait_static_method_call(bh: &mut BenchHarness) { + let s = Struct { field: 10 }; + bh.iter(|| { + s.method(); + }); + } + + // Overhead of various match forms + + #[bench] + fn match_option_some(bh: &mut BenchHarness) { + let x = Some(10); + bh.iter(|| { + let _q = match x { + Some(y) => y, + None => 11 + }; + }); + } + + #[bench] + fn match_vec_pattern(bh: &mut BenchHarness) { + let x = [1,2,3,4,5,6]; + bh.iter(|| { + let _q = match x { + [1,2,3,..] => 10, + _ => 11 + }; + }); + } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 5d986a73ca1..44d78be93d6 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -45,9 +45,9 @@ use default::Default; use fmt; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize}; use kinds::Send; +use mem; use str::OwnedStr; use to_str::ToStr; -use util; use vec; /// The option type @@ -285,7 +285,7 @@ impl<T> Option<T> { /// Take the value out of the option, leaving a `None` in its place. #[inline] pub fn take(&mut self) -> Option<T> { - util::replace(self, None) + mem::replace(self, None) } /// Filters an optional value using a given function. diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index f113b2f17eb..471ec050192 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -40,6 +40,7 @@ pub use result::{Result, Ok, Err}; // Reexported functions pub use from_str::from_str; pub use iter::range; +pub use mem::drop; // Reexported types and traits @@ -85,7 +86,3 @@ pub use task::spawn; // Reexported statics #[cfg(not(test))] pub use gc::GC; - -/// Disposes of a value. -#[inline] -pub fn drop<T>(_x: T) { } diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 484f81f277f..80439d69899 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -18,7 +18,6 @@ use iter::{range, Iterator}; use mem; use option::{Option, Some, None}; use unstable::intrinsics; -use util::swap; #[cfg(not(test))] use cmp::{Eq, Ord}; @@ -152,7 +151,7 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) { */ #[inline] pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T { - swap(cast::transmute(dest), &mut src); // cannot overlap + mem::swap(cast::transmute(dest), &mut src); // cannot overlap src } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 4f65e61ec48..c0f4efba0d1 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -636,8 +636,8 @@ fn test_repr() { use str; use str::Str; use io::stdio::println; - use util::swap; use char::is_alphabetic; + use mem::swap; fn exact_test<T>(t: &T, e:&str) { let mut m = io::MemWriter::new(); diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 526ad60bb21..cef03d66923 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -72,7 +72,7 @@ mod imp { #[cfg(not(test))] use str; use unstable::finally::Finally; use unstable::mutex::{Mutex, MUTEX_INIT}; - use util; + use mem; #[cfg(not(test))] use vec; static mut global_args_ptr: uint = 0; @@ -93,7 +93,7 @@ mod imp { pub fn take() -> Option<~[~str]> { with_lock(|| unsafe { let ptr = get_global_ptr(); - let val = util::replace(&mut *ptr, None); + let val = mem::replace(&mut *ptr, None); val.as_ref().map(|s: &~~[~str]| (**s).clone()) }) } diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 6f9be64a73d..185f4b4edd7 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -14,10 +14,10 @@ use cast; use iter::Iterator; +use mem; use option::{Some, None}; use ptr::RawPtr; use unstable::sync::Exclusive; -use util; use vec::OwnedVector; type Queue = Exclusive<~[proc()]>; @@ -60,7 +60,7 @@ pub fn run() { QUEUE = 0 as *mut Queue; let mut vec = None; state.with(|arr| { - vec = Some(util::replace(arr, ~[])); + vec = Some(mem::replace(arr, ~[])); }); vec.take_unwrap() }; diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 9aece13b84c..2f4e705735e 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -60,6 +60,7 @@ use c_str::CString; use cast; use fmt; use kinds::Send; +use mem; use option::{Some, None, Option}; use prelude::drop; use ptr::RawPtr; @@ -69,7 +70,6 @@ use rt::task::Task; use str::Str; use task::TaskResult; use unstable::intrinsics; -use util; use uw = self::libunwind; @@ -470,7 +470,7 @@ fn begin_unwind_inner(msg: ~Any, file: &'static str, line: uint) -> ! { n, msg_s, file, line); task = Local::take(); - match util::replace(&mut task.stderr, Some(stderr)) { + match mem::replace(&mut task.stderr, Some(stderr)) { Some(prev) => { Local::put(task); drop(prev); diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 624a5aa72de..f57c5bc649a 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -15,7 +15,6 @@ use container::{Container, Map, Mutable, MutableMap}; use iter::{Extendable, FromIterator, Iterator}; use mem; use uint; -use util::replace; use mem::init; use vec; use ptr::RawPtr; @@ -429,7 +428,7 @@ fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T, } External(stored_key, ref mut stored_value) if stored_key == key => { // swap in the new value and return the old. - return Some(replace(stored_value, value)); + return Some(mem::replace(stored_value, value)); } _ => {} } @@ -437,7 +436,7 @@ fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T, // conflict, an external node with differing keys: we have to // split the node, so we need the old value by value; hence we // have to move out of `child`. - match replace(child, Nothing) { + match mem::replace(child, Nothing) { External(stored_key, stored_value) => { let mut new = ~TrieNode::new(); insert(&mut new.count, @@ -456,7 +455,7 @@ fn remove<T>(count: &mut uint, child: &mut Child<T>, key: uint, idx: uint) -> Option<T> { let (ret, this) = match *child { External(stored, _) if stored == key => { - match replace(child, Nothing) { + match mem::replace(child, Nothing) { External(_, value) => (Some(value), true), _ => fail!() } diff --git a/src/libstd/util.rs b/src/libstd/util.rs deleted file mode 100644 index 644b5cefdc8..00000000000 --- a/src/libstd/util.rs +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Miscellaneous helpers for common patterns - -use cast; -use mem; -use ptr; - -/// The identity function. -#[inline] -pub fn id<T>(x: T) -> T { x } - -/** - * Swap the values at two mutable locations of the same type, without - * deinitialising or copying either one. - */ -#[inline] -pub fn swap<T>(x: &mut T, y: &mut T) { - unsafe { - // Give ourselves some scratch space to work with - let mut t: T = mem::uninit(); - - // Perform the swap, `&mut` pointers never alias - ptr::copy_nonoverlapping_memory(&mut t, &*x, 1); - ptr::copy_nonoverlapping_memory(x, &*y, 1); - ptr::copy_nonoverlapping_memory(y, &t, 1); - - // y and t now point to the same thing, but we need to completely forget `tmp` - // because it's no longer relevant. - cast::forget(t); - } -} - -/** - * Replace the value at a mutable location with a new one, returning the old - * value, without deinitialising or copying either one. - */ -#[inline] -pub fn replace<T>(dest: &mut T, mut src: T) -> T { - swap(dest, &mut src); - src -} - -/// A type with no inhabitants -pub enum Void { } - -impl Void { - /// A utility function for ignoring this uninhabited type - pub fn uninhabited(self) -> ! { - match self { - // Nothing to match on - } - } -} - - -#[cfg(test)] -mod tests { - use super::*; - use prelude::*; - - #[test] - fn identity_crisis() { - // Writing a test for the identity function. How did it come to this? - let x = ~[(5, false)]; - //FIXME #3387 assert!(x.eq(id(x.clone()))); - let y = x.clone(); - assert!(x.eq(&id(y))); - } - - #[test] - fn test_swap() { - let mut x = 31337; - let mut y = 42; - swap(&mut x, &mut y); - assert_eq!(x, 42); - assert_eq!(y, 31337); - } - - #[test] - fn test_replace() { - let mut x = Some(~"test"); - let y = replace(&mut x, None); - assert!(x.is_none()); - assert!(y.is_some()); - } -} - -/// Completely miscellaneous language-construct benchmarks. -#[cfg(test)] -mod bench { - - use extra::test::BenchHarness; - use option::{Some,None}; - - // Static/dynamic method dispatch - - struct Struct { - field: int - } - - trait Trait { - fn method(&self) -> int; - } - - impl Trait for Struct { - fn method(&self) -> int { - self.field - } - } - - #[bench] - fn trait_vtable_method_call(bh: &mut BenchHarness) { - let s = Struct { field: 10 }; - let t = &s as &Trait; - bh.iter(|| { - t.method(); - }); - } - - #[bench] - fn trait_static_method_call(bh: &mut BenchHarness) { - let s = Struct { field: 10 }; - bh.iter(|| { - s.method(); - }); - } - - // Overhead of various match forms - - #[bench] - fn match_option_some(bh: &mut BenchHarness) { - let x = Some(10); - bh.iter(|| { - let _q = match x { - Some(y) => y, - None => 11 - }; - }); - } - - #[bench] - fn match_vec_pattern(bh: &mut BenchHarness) { - let x = [1,2,3,4,5,6]; - bh.iter(|| { - let _q = match x { - [1,2,3,..] => 10, - _ => 11 - }; - }); - } -} diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index de865434a3e..b58e0820cfd 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -121,7 +121,6 @@ use kinds::marker; use uint; use unstable::finally::Finally; use unstable::raw::{Repr, Slice, Vec}; -use util; /** * Creates and initializes an owned vector. @@ -1799,7 +1798,7 @@ impl<T:Eq> OwnedEqVector<T> for ~[T] { if *p_r != *p_wm1 { if r != w { let p_w = ptr::mut_offset(p_wm1, 1); - util::swap(&mut *p_r, &mut *p_w); + mem::swap(&mut *p_r, &mut *p_w); } w += 1; } @@ -1994,7 +1993,7 @@ fn merge_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) { } } - util::swap(&mut buf_dat, &mut buf_tmp); + mem::swap(&mut buf_dat, &mut buf_tmp); width *= 2; } @@ -2374,7 +2373,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { #[inline] fn move_from(self, mut src: ~[T], start: uint, end: uint) -> uint { for (a, b) in self.mut_iter().zip(src.mut_slice(start, end).mut_iter()) { - util::swap(a, b); + mem::swap(a, b); } cmp::min(self.len(), end-start) } @@ -2757,14 +2756,14 @@ impl<'a, T> Iterator<&'a mut [T]> for MutSplits<'a, T> { match self.v.iter().position(|x| (self.pred)(x)) { None => { self.finished = true; - let tmp = util::replace(&mut self.v, &mut []); + let tmp = mem::replace(&mut self.v, &mut []); let len = tmp.len(); let (head, tail) = tmp.mut_split_at(len); self.v = tail; Some(head) } Some(idx) => { - let tmp = util::replace(&mut self.v, &mut []); + let tmp = mem::replace(&mut self.v, &mut []); let (head, tail) = tmp.mut_split_at(idx); self.v = tail.mut_slice_from(1); Some(head) @@ -2792,11 +2791,11 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplits<'a, T> { match self.v.iter().rposition(|x| (self.pred)(x)) { None => { self.finished = true; - let tmp = util::replace(&mut self.v, &mut []); + let tmp = mem::replace(&mut self.v, &mut []); Some(tmp) } Some(idx) => { - let tmp = util::replace(&mut self.v, &mut []); + let tmp = mem::replace(&mut self.v, &mut []); let (head, tail) = tmp.mut_split_at(idx); self.v = head; Some(tail.mut_slice_from(1)) @@ -2820,7 +2819,7 @@ impl<'a, T> Iterator<&'a mut [T]> for MutChunks<'a, T> { None } else { let sz = cmp::min(self.v.len(), self.chunk_size); - let tmp = util::replace(&mut self.v, &mut []); + let tmp = mem::replace(&mut self.v, &mut []); let (head, tail) = tmp.mut_split_at(sz); self.v = tail; Some(head) @@ -2847,7 +2846,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> { } else { let remainder = self.v.len() % self.chunk_size; let sz = if remainder != 0 { remainder } else { self.chunk_size }; - let tmp = util::replace(&mut self.v, &mut []); + let tmp = mem::replace(&mut self.v, &mut []); let tmp_len = tmp.len(); let (head, tail) = tmp.mut_split_at(tmp_len - sz); self.v = head; |
