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

@@ -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]);
}