Skip to content

Commit

Permalink
improve the performance of the vec![] macro
Browse files Browse the repository at this point in the history
Closes #17865
  • Loading branch information
thestinger committed Oct 10, 2014
1 parent 310f2de commit 02d976a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Expand Up @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/net/tcp.rs
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/lib.rs
Expand Up @@ -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![]
}
16 changes: 7 additions & 9 deletions src/libstd/macros.rs
Expand Up @@ -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.
///
Expand Down

5 comments on commit 02d976a

@bors
Copy link
Contributor

@bors bors commented on 02d976a Oct 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 02d976a Oct 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/vec = 02d976a into auto

@bors
Copy link
Contributor

@bors bors commented on 02d976a Oct 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/vec = 02d976a merged ok, testing candidate = 1add4de

@bors
Copy link
Contributor

@bors bors commented on 02d976a Oct 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 02d976a Oct 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1add4de

Please sign in to comment.