Some perf fixes, although vec::slice is still too slow (Issue #2719)
This commit is contained in:
parent
7adad4c6cb
commit
b19c98ea9a
@ -1727,7 +1727,7 @@ mod unsafe {
|
||||
vec::reserve(v, len + 1u);
|
||||
vec::as_buf(v) {|b| ptr::memcpy(b, buf, len); }
|
||||
vec::unsafe::set_len(v, len);
|
||||
v += [0u8];
|
||||
vec::push(v, 0u8);
|
||||
|
||||
assert is_utf8(v);
|
||||
ret ::unsafe::transmute(v);
|
||||
|
@ -255,14 +255,18 @@ pure fn slice<T: copy>(v: [const T]/&, start: uint, end: uint) -> [T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let mut result = [];
|
||||
unchecked{reserve(result, end - start)}
|
||||
|
||||
// unchecked {
|
||||
// push_all(result, view(v, start, end));
|
||||
// }
|
||||
|
||||
let mut i = start;
|
||||
while i < end { result += [v[i]]; i += 1u; }
|
||||
ret result;
|
||||
}
|
||||
|
||||
#[doc = "Return a slice that points into another slice."]
|
||||
pure fn view<T: copy>(v: [T]/&, start: uint, end: uint) -> [T]/&a {
|
||||
pure fn view<T: copy>(v: [const T]/&a, start: uint, end: uint) -> [T]/&a {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
unpack_slice(v) {|p, _len|
|
||||
@ -454,6 +458,7 @@ fn push_slow<T>(&v: [const T], +initval: T) {
|
||||
|
||||
#[inline(always)]
|
||||
fn push_all<T: copy>(&v: [const T], rhs: [const T]/&) {
|
||||
reserve(v, v.len() + rhs.len());
|
||||
for uint::range(0u, rhs.len()) {|i|
|
||||
push(v, rhs[i]);
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ impl writer for writer {
|
||||
write_vuint(self.writer, tag_id);
|
||||
|
||||
// Write a placeholder four-byte size.
|
||||
self.size_positions += [self.writer.tell()];
|
||||
vec::push(self.size_positions, self.writer.tell());
|
||||
let zeroes: [u8]/& = [0u8, 0u8, 0u8, 0u8]/&;
|
||||
self.writer.write(zeroes);
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ fn merge_sort<T: copy>(le: le<T>, v: [const T]) -> [T] {
|
||||
let mut b_ix = 0u;
|
||||
while a_ix < a_len && b_ix < b_len {
|
||||
if le(a[a_ix], b[b_ix]) {
|
||||
rs += [a[a_ix]];
|
||||
vec::push(rs, a[a_ix]);
|
||||
a_ix += 1u;
|
||||
} else { rs += [b[b_ix]]; b_ix += 1u; }
|
||||
} else { vec::push(rs, b[b_ix]); b_ix += 1u; }
|
||||
}
|
||||
rs += vec::slice(a, a_ix, a_len);
|
||||
rs += vec::slice(b, b_ix, b_len);
|
||||
|
@ -36,7 +36,7 @@ fn sort_and_fmt(mm: hashmap<[u8], uint>, total: uint) -> str {
|
||||
|
||||
// map -> [(k,%)]
|
||||
mm.each(fn&(key: [u8], val: uint) -> bool {
|
||||
pairs += [(key, pct(val, total))];
|
||||
vec::push(pairs, (key, pct(val, total)));
|
||||
ret true;
|
||||
});
|
||||
|
||||
|
@ -72,7 +72,7 @@ fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
|
||||
for uint::range(0_u, size/8_u) {
|
||||
|j|
|
||||
let x = {re: xincr*(j as f64) - 1.5f64, im: y};
|
||||
crv += [fillbyte(x, incr)];
|
||||
vec::push(crv, fillbyte(x, incr));
|
||||
};
|
||||
comm::send(ch, {i:i, b:crv});
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ fn calc(children: uint, parent_ch: comm::chan<msg>) {
|
||||
iter::repeat (children) {||
|
||||
alt check comm::recv(port) {
|
||||
ready(child_ch) {
|
||||
child_chs += [child_ch];
|
||||
vec::push(child_chs, child_ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// xfail-test
|
||||
fn main() {
|
||||
let vec<int> v = [1,2,3,4,5];
|
||||
auto v2 = v.(1,2);
|
||||
assert (v2.(0) == 2);
|
||||
assert (v2.(1) == 3);
|
||||
let v = [1,2,3,4,5];
|
||||
let v2 = vec::slice(v, 1, 3);
|
||||
assert (v2[0] == 2);
|
||||
assert (v2[1] == 3);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user