1
Fork 0

Some perf fixes, although vec::slice is still too slow (Issue #2719)

This commit is contained in:
Eric Holk 2012-06-25 16:22:22 -07:00
parent 7adad4c6cb
commit b19c98ea9a
8 changed files with 18 additions and 14 deletions

View file

@ -1727,7 +1727,7 @@ mod unsafe {
vec::reserve(v, len + 1u); vec::reserve(v, len + 1u);
vec::as_buf(v) {|b| ptr::memcpy(b, buf, len); } vec::as_buf(v) {|b| ptr::memcpy(b, buf, len); }
vec::unsafe::set_len(v, len); vec::unsafe::set_len(v, len);
v += [0u8]; vec::push(v, 0u8);
assert is_utf8(v); assert is_utf8(v);
ret ::unsafe::transmute(v); ret ::unsafe::transmute(v);

View file

@ -255,14 +255,18 @@ pure fn slice<T: copy>(v: [const T]/&, start: uint, end: uint) -> [T] {
assert (start <= end); assert (start <= end);
assert (end <= len(v)); assert (end <= len(v));
let mut result = []; let mut result = [];
unchecked{reserve(result, end - start)}
// unchecked {
// push_all(result, view(v, start, end));
// }
let mut i = start; let mut i = start;
while i < end { result += [v[i]]; i += 1u; } while i < end { result += [v[i]]; i += 1u; }
ret result; ret result;
} }
#[doc = "Return a slice that points into another slice."] #[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 (start <= end);
assert (end <= len(v)); assert (end <= len(v));
unpack_slice(v) {|p, _len| unpack_slice(v) {|p, _len|
@ -454,6 +458,7 @@ fn push_slow<T>(&v: [const T], +initval: T) {
#[inline(always)] #[inline(always)]
fn push_all<T: copy>(&v: [const T], rhs: [const T]/&) { fn push_all<T: copy>(&v: [const T], rhs: [const T]/&) {
reserve(v, v.len() + rhs.len());
for uint::range(0u, rhs.len()) {|i| for uint::range(0u, rhs.len()) {|i|
push(v, rhs[i]); push(v, rhs[i]);
} }

View file

@ -193,7 +193,7 @@ impl writer for writer {
write_vuint(self.writer, tag_id); write_vuint(self.writer, tag_id);
// Write a placeholder four-byte size. // 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]/&; let zeroes: [u8]/& = [0u8, 0u8, 0u8, 0u8]/&;
self.writer.write(zeroes); self.writer.write(zeroes);
} }

View file

@ -43,9 +43,9 @@ fn merge_sort<T: copy>(le: le<T>, v: [const T]) -> [T] {
let mut b_ix = 0u; let mut b_ix = 0u;
while a_ix < a_len && b_ix < b_len { while a_ix < a_len && b_ix < b_len {
if le(a[a_ix], b[b_ix]) { if le(a[a_ix], b[b_ix]) {
rs += [a[a_ix]]; vec::push(rs, a[a_ix]);
a_ix += 1u; 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(a, a_ix, a_len);
rs += vec::slice(b, b_ix, b_len); rs += vec::slice(b, b_ix, b_len);

View file

@ -36,7 +36,7 @@ fn sort_and_fmt(mm: hashmap<[u8], uint>, total: uint) -> str {
// map -> [(k,%)] // map -> [(k,%)]
mm.each(fn&(key: [u8], val: uint) -> bool { mm.each(fn&(key: [u8], val: uint) -> bool {
pairs += [(key, pct(val, total))]; vec::push(pairs, (key, pct(val, total)));
ret true; ret true;
}); });

View file

@ -72,7 +72,7 @@ fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
for uint::range(0_u, size/8_u) { for uint::range(0_u, size/8_u) {
|j| |j|
let x = {re: xincr*(j as f64) - 1.5f64, im: y}; 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}); comm::send(ch, {i:i, b:crv});
} }

View file

@ -21,7 +21,7 @@ fn calc(children: uint, parent_ch: comm::chan<msg>) {
iter::repeat (children) {|| iter::repeat (children) {||
alt check comm::recv(port) { alt check comm::recv(port) {
ready(child_ch) { ready(child_ch) {
child_chs += [child_ch]; vec::push(child_chs, child_ch);
} }
} }
} }

View file

@ -1,7 +1,6 @@
// xfail-test
fn main() { fn main() {
let vec<int> v = [1,2,3,4,5]; let v = [1,2,3,4,5];
auto v2 = v.(1,2); let v2 = vec::slice(v, 1, 3);
assert (v2.(0) == 2); assert (v2[0] == 2);
assert (v2.(1) == 3); assert (v2[1] == 3);
} }