提交 0c42a3ff 编写于 作者: E Eric Holk

vec::append reuses its left hand side when possible. (issue #2719)

上级 3297d465
......@@ -484,10 +484,9 @@ fn push_all_move<T>(&v: [const T]/~, -rhs: [const T]/~) {
// Appending
#[inline(always)]
pure fn append<T: copy>(lhs: [T]/&, rhs: [const T]/&) -> [T]/~ {
let mut v = []/~;
pure fn append<T: copy>(+lhs: [T]/~, rhs: [const T]/&) -> [T]/~ {
let mut v <- lhs;
unchecked {
push_all(v, lhs);
push_all(v, rhs);
}
ret v;
......
......@@ -22,6 +22,7 @@ fn main(argv: [str]/~) {
#bench[shift_push];
#bench[read_line];
#bench[str_set];
#bench[vec_plus];
#bench[vec_append];
#bench[vec_push_all];
}
......@@ -75,11 +76,12 @@ fn str_set() {
}
}
fn vec_append() {
fn vec_plus() {
let r = rand::rng();
let mut v = []/~;
for uint::range(0, 1500) {|i|
let mut v = []/~;
let mut i = 0;
while i < 1500 {
let rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
if r.gen_bool() {
v += rv;
......@@ -87,6 +89,24 @@ fn vec_append() {
else {
v = rv + v;
}
i += 1;
}
}
fn vec_append() {
let r = rand::rng();
let mut v = []/~;
let mut i = 0;
while i < 1500 {
let rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
if r.gen_bool() {
v = vec::append(v, rv);
}
else {
v = vec::append(rv, v);
}
i += 1;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册