improve the performance of the vec![] macro

Closes #17865
This commit is contained in:
Daniel Micay 2014-10-10 06:19:40 -04:00
parent 310f2deb99
commit 02d976a7f9
5 changed files with 13 additions and 14 deletions

View File

@ -2331,7 +2331,7 @@ mod tests {
fn test_into_vec() {
let xs = box [1u, 2, 3];
let ys = xs.into_vec();
assert_eq!(ys.as_slice(), [1u, 2, 3]);
assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice());
}
}

View File

@ -2650,7 +2650,7 @@ mod tests {
fn test_into_boxed_slice() {
let xs = vec![1u, 2, 3];
let ys = xs.into_boxed_slice();
assert_eq!(ys.as_slice(), [1u, 2, 3]);
assert_eq!(ys.as_slice(), [1u, 2, 3].as_slice());
}
#[bench]

View File

@ -18,7 +18,6 @@
//! listener (socket server) implements the `Listener` and `Acceptor` traits.
use clone::Clone;
use collections::MutableSeq;
use io::IoResult;
use iter::Iterator;
use slice::ImmutableSlice;

View File

@ -272,7 +272,9 @@ mod std {
// The test runner calls ::std::os::args() but really wants realstd
#[cfg(test)] pub use realstd::os as os;
// The test runner requires std::slice::Vector, so re-export std::slice just for it.
#[cfg(test)] pub use slice;
//
// It is also used in vec![]
pub use slice;
pub use collections; // vec!() uses MutableSeq
pub use boxed; // used for vec![]
}

View File

@ -323,16 +323,14 @@ macro_rules! try(
/// Create a `std::vec::Vec` containing the arguments.
#[macro_export]
macro_rules! vec(
($($e:expr),*) => ({
// leading _ to allow empty construction without a warning.
let mut _temp = ::std::vec::Vec::new();
$(_temp.push($e);)*
_temp
macro_rules! vec[
($($x:expr),*) => ({
use std::slice::BoxedSlice;
let xs: ::std::boxed::Box<[_]> = box [$($x),*];
xs.into_vec()
});
($($e:expr),+,) => (vec!($($e),+))
)
($($x:expr,)*) => (vec![$($x),*])
]
/// A macro to select an event from a number of receivers.
///