diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 90138468fa8..7b64f6da0bb 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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); diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index b81073c729f..b58d5b3b3b1 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -255,14 +255,18 @@ pure fn slice(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(v: [T]/&, start: uint, end: uint) -> [T]/&a { +pure fn view(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(&v: [const T], +initval: T) { #[inline(always)] fn push_all(&v: [const T], rhs: [const T]/&) { + reserve(v, v.len() + rhs.len()); for uint::range(0u, rhs.len()) {|i| push(v, rhs[i]); } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 6697c58252e..d02c498025c 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -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); } diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 76c71d7ed2a..5c5a6e09d2f 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -43,9 +43,9 @@ fn merge_sort(le: le, 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); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 4c6cd7d9ae6..26e8b938468 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -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; }); diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 91b263f997b..7254b5bbb9e 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -72,7 +72,7 @@ fn chanmb(i: uint, size: uint, ch: comm::chan) -> () 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}); } diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index 42fe44e2697..5faf7f85857 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -21,7 +21,7 @@ fn calc(children: uint, parent_ch: comm::chan) { iter::repeat (children) {|| alt check comm::recv(port) { ready(child_ch) { - child_chs += [child_ch]; + vec::push(child_chs, child_ch); } } } diff --git a/src/test/run-pass/vec-slice.rs b/src/test/run-pass/vec-slice.rs index c03b8c4611a..b8ec6563a96 100644 --- a/src/test/run-pass/vec-slice.rs +++ b/src/test/run-pass/vec-slice.rs @@ -1,7 +1,6 @@ -// xfail-test fn main() { - let vec 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); }