Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Demode vec::push (and convert to method)

  • Loading branch information...
commit 67a8e7128aea292445b763b47b04bc5f4fd43cb2 1 parent cd79e1d
@nikomatsakis nikomatsakis authored
Showing with 684 additions and 670 deletions.
  1. +1 −1  doc/rust.md
  2. +1 −1  doc/tutorial.md
  3. +2 −2 src/cargo/cargo.rs
  4. +1 −1  src/compiletest/compiletest.rs
  5. +3 −3 src/compiletest/header.rs
  6. +1 −1  src/compiletest/procsrv.rs
  7. +1 −1  src/compiletest/runtest.rs
  8. +2 −2 src/fuzzer/cycles.rs
  9. +2 −2 src/fuzzer/fuzzer.rs
  10. +4 −4 src/fuzzer/ivec_fuzz.rs
  11. +1 −1  src/fuzzer/rand_util.rs
  12. +2 −0  src/libcore/core.rs
  13. +4 −4 src/libcore/dvec.rs
  14. +14 −14 src/libcore/either.rs
  15. +2 −2 src/libcore/extfmt.rs
  16. +2 −2 src/libcore/flate.rs
  17. +1 −1  src/libcore/float.rs
  18. +9 −9 src/libcore/io.rs
  19. +1 −1  src/libcore/os.rs
  20. +5 −5 src/libcore/path.rs
  21. +1 −1  src/libcore/pipes.rs
  22. +1 −1  src/libcore/private.rs
  23. +1 −1  src/libcore/rand.rs
  24. +2 −2 src/libcore/result.rs
  25. +6 −6 src/libcore/run.rs
  26. +3 −12 src/libcore/send_map.rs
  27. +11 −12 src/libcore/str.rs
  28. +113 −76 src/libcore/vec.rs
  29. +2 −2 src/libstd/arc.rs
  30. +6 −6 src/libstd/base64.rs
  31. +2 −2 src/libstd/deque.rs
  32. +1 −1  src/libstd/ebml.rs
  33. +1 −1  src/libstd/ebml2.rs
  34. +10 −11 src/libstd/getopts.rs
  35. +17 −12 src/libstd/json.rs
  36. +2 −2 src/libstd/md4.rs
  37. +1 −1  src/libstd/net_ip.rs
  38. +2 −2 src/libstd/net_tcp.rs
  39. +1 −1  src/libstd/net_url.rs
  40. +1 −1  src/libstd/par.rs
  41. +1 −1  src/libstd/rope.rs
  42. +2 −2 src/libstd/sort.rs
  43. +4 −4 src/libstd/sync.rs
  44. +2 −2 src/libstd/test.rs
  45. +2 −2 src/libsyntax/ast_map.rs
  46. +2 −2 src/libsyntax/ast_util.rs
  47. +1 −1  src/libsyntax/attr.rs
  48. +2 −2 src/libsyntax/codemap.rs
  49. +1 −1  src/libsyntax/ext/auto_serialize2.rs
  50. +1 −1  src/libsyntax/ext/base.rs
  51. +1 −1  src/libsyntax/ext/build.rs
  52. +2 −2 src/libsyntax/ext/fmt.rs
  53. +1 −1  src/libsyntax/ext/pipes/liveness.rs
  54. +42 −44 src/libsyntax/ext/pipes/pipec.rs
  55. +6 −7 src/libsyntax/ext/simplext.rs
  56. +12 −12 src/libsyntax/ext/tt/macro_parser.rs
  57. +2 −2 src/libsyntax/ext/tt/transcribe.rs
  58. +4 −6 src/libsyntax/fold.rs
  59. +7 −7 src/libsyntax/parse/comments.rs
  60. +2 −2 src/libsyntax/parse/common.rs
  61. +3 −3 src/libsyntax/parse/eval.rs
  62. +68 −68 src/libsyntax/parse/parser.rs
  63. +21 −21 src/rustc/back/link.rs
  64. +5 −5 src/rustc/back/rpath.rs
  65. +1 −1  src/rustc/back/upcall.rs
  66. +2 −2 src/rustc/driver/driver.rs
  67. +2 −2 src/rustc/front/test.rs
  68. +4 −4 src/rustc/metadata/cstore.rs
  69. +20 −20 src/rustc/metadata/decoder.rs
  70. +27 −28 src/rustc/metadata/encoder.rs
  71. +5 −5 src/rustc/metadata/filesearch.rs
  72. +1 −1  src/rustc/metadata/loader.rs
  73. +8 −8 src/rustc/metadata/tydecode.rs
  74. +1 −1  src/rustc/middle/capture.rs
  75. +2 −2 src/rustc/middle/check_alt.rs
  76. +1 −1  src/rustc/middle/freevars.rs
  77. +4 −4 src/rustc/middle/kind.rs
  78. +1 −1  src/rustc/middle/lint.rs
  79. +3 −3 src/rustc/middle/liveness.rs
  80. +1 −1  src/rustc/middle/pat_util.rs
  81. +1 −1  src/rustc/middle/region.rs
  82. +3 −3 src/rustc/middle/resolve.rs
  83. +6 −6 src/rustc/middle/trans/alt.rs
  84. +8 −8 src/rustc/middle/trans/base.rs
  85. +1 −1  src/rustc/middle/trans/build.rs
  86. +5 −5 src/rustc/middle/trans/callee.rs
  87. +10 −10 src/rustc/middle/trans/closure.rs
  88. +12 −12 src/rustc/middle/trans/common.rs
  89. +2 −2 src/rustc/middle/trans/debuginfo.rs
  90. +2 −2 src/rustc/middle/trans/expr.rs
  91. +11 −11 src/rustc/middle/trans/foreign.rs
  92. +1 −1  src/rustc/middle/trans/monomorphize.rs
  93. +2 −2 src/rustc/middle/trans/tvec.rs
  94. +5 −5 src/rustc/middle/trans/type_of.rs
  95. +23 −23 src/rustc/middle/ty.rs
  96. +6 −5 src/rustc/middle/typeck/check.rs
  97. +2 −2 src/rustc/middle/typeck/check/regionmanip.rs
  98. +5 −5 src/rustc/middle/typeck/check/vtable.rs
  99. +1 −1  src/rustc/middle/typeck/check/writeback.rs
  100. +4 −5 src/rustc/middle/typeck/coherence.rs
  101. +4 −4 src/rustc/middle/typeck/infer/region_var_bindings.rs
  102. +1 −1  src/rustc/middle/typeck/infer/resolve.rs
  103. +1 −1  src/rustc/middle/typeck/infer/unify.rs
  104. +1 −1  src/rustc/util/common.rs
  105. +3 −3 src/rustc/util/ppaux.rs
  106. +1 −1  src/rustdoc/extract.rs
  107. +2 −2 src/rustdoc/path_pass.rs
  108. +3 −3 src/test/bench/core-std.rs
  109. +1 −1  src/test/bench/core-vec-append.rs
  110. +1 −1  src/test/bench/graph500-bfs.rs
  111. +1 −1  src/test/bench/msgsend-pipes-shared.rs
  112. +1 −1  src/test/bench/msgsend-pipes.rs
  113. +2 −2 src/test/bench/msgsend-ring-mutex-arcs.rs
  114. +1 −1  src/test/bench/msgsend-ring-pipes.rs
  115. +2 −2 src/test/bench/msgsend-ring-rw-arcs.rs
  116. +1 −1  src/test/bench/msgsend-ring.rs
  117. +1 −1  src/test/bench/msgsend.rs
  118. +1 −1  src/test/bench/shootout-chameneos-redux.rs
  119. +2 −2 src/test/bench/shootout-k-nucleotide-pipes.rs
  120. +1 −1  src/test/bench/shootout-k-nucleotide.rs
  121. +1 −1  src/test/bench/shootout-mandelbrot.rs
  122. +1 −1  src/test/bench/shootout-pfib.rs
  123. +1 −1  src/test/bench/task-perf-one-million.rs
  124. +3 −4 src/test/bench/task-perf-word-count-generic.rs
  125. +1 −1  src/test/compile-fail/purity-infer-fail.rs
  126. +2 −2 src/test/run-fail/zip-different-lengths.rs
  127. +1 −1  src/test/run-pass/auto-ref-sliceable.rs
  128. +0 −17 src/test/run-pass/autoref-vec-push.rs
  129. +1 −1  src/test/run-pass/borrowck-mut-uniq.rs
  130. +6 −1 src/test/run-pass/issue-2904.rs
  131. +1 −1  src/test/run-pass/task-comm-3.rs
  132. +2 −2 src/test/run-pass/task-comm.rs
  133. +1 −1  src/test/run-pass/vec-push.rs
  134. +2 −2 src/test/run-pass/zip-same-length.rs
View
2  doc/rust.md
@@ -1016,7 +1016,7 @@ fn iter<T>(seq: ~[T], f: fn(T)) {
}
fn map<T, U>(seq: ~[T], f: fn(T) -> U) -> ~[U] {
let mut acc = ~[];
- for seq.each |elt| { vec::push(acc, f(elt)); }
+ for seq.each |elt| { acc.push(f(elt)); }
acc
}
~~~~
View
2  doc/tutorial.md
@@ -1651,7 +1651,7 @@ may be invoked on multiple types.
fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
- vec::push(accumulator, function(element));
+ accumulator.push(function(element));
}
return accumulator;
}
View
4 src/cargo/cargo.rs
@@ -345,7 +345,7 @@ fn load_crate(filename: &Path) -> Option<Crate> {
match *ps.interner.get(attr_name) {
~"std" | ~"core" => (),
- _ => vec::push(e.deps, query)
+ _ => e.deps.push(query)
}
}
_ => ()
@@ -801,7 +801,7 @@ fn install_source(c: &Cargo, path: &Path) {
let mut cratefiles = ~[];
for os::walk_dir(&Path(".")) |p| {
if p.filetype() == Some(~".rc") {
- vec::push(cratefiles, *p);
+ cratefiles.push(*p);
}
}
View
2  src/compiletest/compiletest.rs
@@ -141,7 +141,7 @@ fn make_tests(config: config) -> ~[test::TestDesc] {
let file = copy *file;
debug!("inspecting file %s", file.to_str());
if is_test(config, file) {
- vec::push(tests, make_test(config, file))
+ tests.push(make_test(config, file))
}
}
return tests;
View
6 src/compiletest/header.rs
@@ -28,7 +28,7 @@ fn load_props(testfile: &Path) -> test_props {
let mut pp_exact = option::None;
for iter_header(testfile) |ln| {
match parse_error_pattern(ln) {
- option::Some(ep) => vec::push(error_patterns, ep),
+ option::Some(ep) => error_patterns.push(ep),
option::None => ()
};
@@ -41,11 +41,11 @@ fn load_props(testfile: &Path) -> test_props {
}
do parse_aux_build(ln).iter |ab| {
- vec::push(aux_builds, ab);
+ aux_builds.push(ab);
}
do parse_exec_env(ln).iter |ee| {
- vec::push(exec_env, ee);
+ exec_env.push(ee);
}
};
return {
View
2  src/compiletest/procsrv.rs
@@ -19,7 +19,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
else { (k,v) }
};
if str::ends_with(prog, ~"rustc.exe") {
- vec::push(env, (~"RUST_THREADS", ~"1"));
+ env.push((~"RUST_THREADS", ~"1"));
}
return env;
}
View
2  src/compiletest/runtest.rs
@@ -121,7 +121,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
procres);
}
- vec::push(srcs, procres.stdout);
+ srcs.push(procres.stdout);
round += 1;
}
View
4 src/fuzzer/cycles.rs
@@ -62,7 +62,7 @@ fn test_cycles(r : rand::rng, k: uint, n: uint)
// Create a graph with no edges
range(0u, vlen) {|_i|
- vec::push(v, empty_pointy());
+ v.push(empty_pointy());
}
// Fill in the graph with random edges, with density k/n
@@ -77,7 +77,7 @@ fn test_cycles(r : rand::rng, k: uint, n: uint)
// https://github.com/mozilla/rust/issues/1899
if (likelihood(r, k, n)) { v[i].m = [p(choice(r, v))]; }
- if (likelihood(r, k, n)) { vec::push(v[i].n, mut p(choice(r, v))); }
+ if (likelihood(r, k, n)) { v[i].n.push(mut p(choice(r, v))); }
if (likelihood(r, k, n)) { v[i].o = {x: 0, y: p(choice(r, v))}; }
}
View
4 src/fuzzer/fuzzer.rs
@@ -30,7 +30,7 @@ fn contains(haystack: ~str, needle: ~str) -> bool {
fn find_rust_files(files: &mut ~[Path], path: &Path) {
if path.filetype() == Some(~".rs") && !contains(path.to_str(), ~"utf8") {
// ignoring "utf8" tests because something is broken
- vec::push(*files, *path);
+ files.push(*path);
} else if os::path_is_dir(path)
&& !contains(path.to_str(), ~"compile-fail")
&& !contains(path.to_str(), ~"build") {
@@ -124,7 +124,7 @@ fn stash_ty_if(c: fn@(@ast::ty, test_mode)->bool,
e: @ast::ty,
tm: test_mode) {
if c(e, tm) {
- vec::push(*es,*e);
+ es.push(e);
} else {/* now my indices are wrong :( */ }
}
View
8 src/fuzzer/ivec_fuzz.rs
@@ -55,11 +55,11 @@ fn vec_edits<T: copy>(v: ~[T], xs: ~[T]) -> ~[~[T]] {
if Lv != 1u {
// When Lv == 1u, this is redundant with omit.
- vec::push(edits, ~[]);
+ edits.push(~[]);
}
if Lv >= 3u {
// When Lv == 2u, this is redundant with swap.
- vec::push(edits, vec::reversed(v));
+ edits.push(vec::reversed(v));
}
ix(0u, 1u, Lv) {|i| edits += ~[vec_omit(v, i)]; }
ix(0u, 1u, Lv) {|i| edits += ~[vec_dup(v, i)]; }
@@ -69,10 +69,10 @@ fn vec_edits<T: copy>(v: ~[T], xs: ~[T]) -> ~[~[T]] {
ix(0u, 1u, len(xs)) {|j|
ix(0u, 1u, Lv) {|i|
- vec::push(edits, vec_poke(v, i, xs[j]));
+ edits.push(vec_poke(v, i, xs[j]));
}
ix(0u, 0u, Lv) {|i|
- vec::push(edits, vec_insert(v, i, xs[j]));
+ edits.push(vec_insert(v, i, xs[j]));
}
}
View
2  src/fuzzer/rand_util.rs
@@ -61,7 +61,7 @@ fn weighted_vec<T: copy>(v : ~[weighted<T>]) -> ~[T] {
for {weight: weight, item: item} in v {
let i = 0u;
while i < weight {
- vec::push(r, item);
+ r.push(item);
i += 1u;
}
}
View
2  src/libcore/core.rs
@@ -17,6 +17,7 @@ use tuple::{TupleOps, ExtendedTupleOps};
use str::{StrSlice, UniqueStr};
use vec::{ConstVector, CopyableVector, ImmutableVector};
use vec::{ImmutableEqVector, ImmutableCopyableVector};
+use vec::{MutableVector, MutableCopyableVector};
use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
use iter::{CopyableOrderedIter, Times, TimesIx};
use num::Num;
@@ -33,6 +34,7 @@ export Num, Times, TimesIx;
export StrSlice, UniqueStr;
export ConstVector, CopyableVector, ImmutableVector;
export ImmutableEqVector, ImmutableCopyableVector, IterTraitExtensions;
+export MutableVector, MutableCopyableVector;
export BaseIter, CopyableIter, CopyableOrderedIter, ExtendedIter, EqIter;
export TupleOps, ExtendedTupleOps;
export Ptr;
View
8 src/libcore/dvec.rs
@@ -172,7 +172,7 @@ impl<A> DVec<A> {
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
log(error, ~"a");
self.data <- ~[move t];
- vec::push_all_move(self.data, move data);
+ self.data.push_all_move(move data);
log(error, ~"b");
}
}
@@ -180,7 +180,7 @@ impl<A> DVec<A> {
/// Append a single item to the end of the list
fn push(+t: A) {
self.check_not_borrowed();
- vec::push(self.data, move t);
+ self.data.push(move t);
}
/// Remove and return the first element
@@ -240,7 +240,7 @@ impl<A: Copy> DVec<A> {
vec::reserve(&mut v, new_len);
let mut i = from_idx;
while i < to_idx {
- vec::push(v, ts[i]);
+ v.push(ts[i]);
i += 1u;
}
move v
@@ -266,7 +266,7 @@ impl<A: Copy> DVec<A> {
}
};
- for ts.each |t| { vec::push(v, *t) };
+ for ts.each |t| { v.push(*t) };
v
}
}
View
28 src/libcore/either.rs
@@ -32,27 +32,27 @@ fn either<T, U, V>(f_left: fn((&T)) -> V,
fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
//! Extracts from a vector of either all the left values
- let mut result: ~[T] = ~[];
- for vec::each(eithers) |elt| {
- match *elt {
- Left(l) => vec::push(result, l),
- _ => { /* fallthrough */ }
+ do vec::build_sized(eithers.len()) |push| {
+ for vec::each(eithers) |elt| {
+ match *elt {
+ Left(ref l) => { push(*l); }
+ _ => { /* fallthrough */ }
+ }
}
}
- move result
}
fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
//! Extracts from a vector of either all the right values
- let mut result: ~[U] = ~[];
- for vec::each(eithers) |elt| {
- match *elt {
- Right(r) => vec::push(result, r),
- _ => { /* fallthrough */ }
+ do vec::build_sized(eithers.len()) |push| {
+ for vec::each(eithers) |elt| {
+ match *elt {
+ Right(ref r) => { push(*r); }
+ _ => { /* fallthrough */ }
+ }
}
}
- move result
}
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
@@ -68,8 +68,8 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
let mut rights: ~[U] = ~[];
for vec::each(eithers) |elt| {
match *elt {
- Left(l) => vec::push(lefts, l),
- Right(r) => vec::push(rights, r)
+ Left(l) => lefts.push(l),
+ Right(r) => rights.push(r)
}
}
return {lefts: move lefts, rights: move rights};
View
4 src/libcore/extfmt.rs
@@ -90,7 +90,7 @@ mod ct {
fn flush_buf(+buf: ~str, &pieces: ~[Piece]) -> ~str {
if str::len(buf) > 0 {
let piece = PieceString(move buf);
- vec::push(pieces, move piece);
+ pieces.push(move piece);
}
return ~"";
}
@@ -110,7 +110,7 @@ mod ct {
} else {
buf = flush_buf(move buf, pieces);
let rs = parse_conversion(s, i, lim, error);
- vec::push(pieces, copy rs.piece);
+ pieces.push(copy rs.piece);
i = rs.next;
}
} else { buf += curr; i += size; }
View
4 src/libcore/flate.rs
@@ -71,12 +71,12 @@ fn test_flate_round_trip() {
let r = rand::Rng();
let mut words = ~[];
for 20.times {
- vec::push(words, r.gen_bytes(r.gen_uint_range(1, 10)));
+ words.push(r.gen_bytes(r.gen_uint_range(1, 10)));
}
for 20.times {
let mut in = ~[];
for 2000.times {
- vec::push_all(in, r.choose(words));
+ in.push_all(r.choose(words));
}
debug!("de/inflate of %u bytes of random word-sequences",
in.len());
View
2  src/libcore/float.rs
@@ -143,7 +143,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
// store the next digit
frac *= 10.0;
let digit = frac as uint;
- vec::push(fractionalParts, digit);
+ fractionalParts.push(digit);
// calculate the next frac
frac -= digit as float;
View
18 src/libcore/io.rs
@@ -76,7 +76,7 @@ impl<T: Reader> T : ReaderUtil {
loop {
let ch = self.read_byte();
if ch == -1 || ch == 10 { break; }
- vec::push(buf, ch as u8);
+ buf.push(ch as u8);
}
str::from_bytes(buf)
}
@@ -94,7 +94,7 @@ impl<T: Reader> T : ReaderUtil {
i += 1;
assert (w > 0);
if w == 1 {
- vec::push(*chars, b0 as char);
+ chars.push(b0 as char);
loop;
}
// can't satisfy this char with the existing data
@@ -113,7 +113,7 @@ impl<T: Reader> T : ReaderUtil {
// See str::char_at
val += ((b0 << ((w + 1) as u8)) as uint)
<< (w - 1) * 6 - w - 1u;
- vec::push(*chars, val as char);
+ chars.push(val as char);
}
return (i, 0);
}
@@ -128,7 +128,7 @@ impl<T: Reader> T : ReaderUtil {
// we're split in a unicode char?
break;
}
- vec::push_all(buf, data);
+ buf.push_all(data);
let (offset, nbreq) = chars_from_bytes::<T>(&buf, &mut chars);
let ncreq = n - chars.len();
// again we either know we need a certain number of bytes
@@ -155,7 +155,7 @@ impl<T: Reader> T : ReaderUtil {
let mut buf: ~[u8] = ~[];
loop {
let ch = self.read_byte();
- if ch < 1 { break; } else { vec::push(buf, ch as u8); }
+ if ch < 1 { break; } else { buf.push(ch as u8); }
}
str::from_bytes(buf)
}
@@ -190,7 +190,7 @@ impl<T: Reader> T : ReaderUtil {
fn read_whole_stream() -> ~[u8] {
let mut buf: ~[u8] = ~[];
- while !self.eof() { vec::push_all(buf, self.read_bytes(2048u)); }
+ while !self.eof() { buf.push_all(self.read_bytes(2048u)); }
move buf
}
@@ -503,7 +503,7 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
let mut bytes: ~[u8] = ~[], i = size, n = n;
while i > 0u {
- vec::push(bytes, (n & 255_u64) as u8);
+ bytes.push((n & 255_u64) as u8);
n >>= 8_u64;
i -= 1u;
}
@@ -535,7 +535,7 @@ fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
let mut i = size;
while i > 0u {
let shift = ((i - 1u) * 8u) as u64;
- vec::push(bytes, (n >> shift) as u8);
+ bytes.push((n >> shift) as u8);
i -= 1u;
}
f(bytes)
@@ -737,7 +737,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str {
let mut v = with_bytes_writer(f);
// Make sure the vector has a trailing null and is proper utf8.
- vec::push(v, 0);
+ v.push(0);
assert str::is_utf8(v);
unsafe { move ::cast::transmute(v) }
View
2  src/libcore/os.rs
@@ -219,7 +219,7 @@ mod global_env {
for vec::each(rustrt::rust_env_pairs()) |p| {
let vs = str::splitn_char(*p, '=', 1u);
assert vec::len(vs) == 2u;
- vec::push(pairs, (copy vs[0], copy vs[1]));
+ pairs.push((copy vs[0], copy vs[1]));
}
move pairs
}
View
10 src/libcore/path.rs
@@ -206,7 +206,7 @@ impl PosixPath : GenericPath {
let mut ss = str::split_nonempty(
*e,
|c| windows::is_sep(c as u8));
- unsafe { vec::push_all_move(v, move ss); }
+ unsafe { v.push_all_move(move ss); }
}
PosixPath { components: move v, ..self }
}
@@ -214,7 +214,7 @@ impl PosixPath : GenericPath {
pure fn push(s: &str) -> PosixPath {
let mut v = copy self.components;
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
- unsafe { vec::push_all_move(v, move ss); }
+ unsafe { v.push_all_move(move ss); }
PosixPath { components: move v, ..self }
}
@@ -400,7 +400,7 @@ impl WindowsPath : GenericPath {
let mut ss = str::split_nonempty(
*e,
|c| windows::is_sep(c as u8));
- unsafe { vec::push_all_move(v, move ss); }
+ unsafe { v.push_all_move(move ss); }
}
return WindowsPath { components: move v, ..self }
}
@@ -408,7 +408,7 @@ impl WindowsPath : GenericPath {
pure fn push(s: &str) -> WindowsPath {
let mut v = copy self.components;
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
- unsafe { vec::push_all_move(v, move ss); }
+ unsafe { v.push_all_move(move ss); }
return WindowsPath { components: move v, ..self }
}
@@ -440,7 +440,7 @@ pure fn normalize(components: &[~str]) -> ~[~str] {
vec::pop(cs);
loop;
}
- vec::push(cs, copy *c);
+ cs.push(copy *c);
}
}
}
View
2  src/libcore/pipes.rs
@@ -1059,7 +1059,7 @@ pub fn PortSet<T: Send>() -> PortSet<T>{
impl<T: Send> PortSet<T> : Recv<T> {
fn add(+port: pipes::Port<T>) {
- vec::push(self.ports, move port)
+ self.ports.push(move port)
}
fn chan() -> Chan<T> {
View
2  src/libcore/private.rs
@@ -564,7 +564,7 @@ pub mod tests {
for uint::range(0u, num_tasks) |_i| {
let total = total.clone();
- vec::push(futures, future::spawn(|| {
+ futures.push(future::spawn(|| {
for uint::range(0u, count) |_i| {
do total.with |count| {
**count += 1u;
View
2  src/libcore/rand.rs
@@ -215,7 +215,7 @@ impl Rng {
let mut r = ~[];
for v.each |item| {
for uint::range(0u, item.weight) |_i| {
- vec::push(r, item.item);
+ r.push(item.item);
}
}
move r
View
4 src/libcore/result.rs
@@ -280,7 +280,7 @@ fn map_vec<T,U:Copy,V:Copy>(
let mut vs: ~[V] = vec::with_capacity(vec::len(ts));
for vec::each(ts) |t| {
match op(t) {
- Ok(v) => vec::push(vs, v),
+ Ok(v) => vs.push(v),
Err(u) => return Err(u)
}
}
@@ -317,7 +317,7 @@ fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
let mut i = 0u;
while i < n {
match op(&ss[i],&ts[i]) {
- Ok(v) => vec::push(vs, v),
+ Ok(v) => vs.push(v),
Err(u) => return Err(u)
}
i += 1u;
View
12 src/libcore/run.rs
@@ -82,10 +82,10 @@ fn with_argv<T>(prog: &str, args: &[~str],
let mut tmps = ~[];
for vec::each(args) |arg| {
let t = @copy *arg;
- vec::push(tmps, t);
- vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b]));
+ tmps.push(t);
+ argptrs.push_all(str::as_c_str(*t, |b| ~[b]));
}
- vec::push(argptrs, ptr::null());
+ argptrs.push(ptr::null());
vec::as_imm_buf(argptrs, |buf, _len| cb(buf))
}
@@ -102,10 +102,10 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
for vec::each(es) |e| {
let (k,v) = copy *e;
let t = @(fmt!("%s=%s", k, v));
- vec::push(tmps, t);
- vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b]));
+ tmps.push(t);
+ ptrs.push_all(str::as_c_str(*t, |b| ~[b]));
}
- vec::push(ptrs, ptr::null());
+ ptrs.push(ptr::null());
vec::as_imm_buf(ptrs, |p, _len|
unsafe { cb(::cast::reinterpret_cast(&p)) }
)
View
15 src/libcore/send_map.rs
@@ -283,18 +283,9 @@ pub mod linear {
FoundEntry(idx) => {
match self.buckets[idx] {
Some(ref bkt) => {
- let ptr = unsafe {
- // FIXME(#3148)--region inference
- // fails to capture needed deps.
- // Here, the bucket value is known to
- // live as long as self, because self
- // is immutable. But the region
- // inference stupidly infers a
- // lifetime for `ref bkt` that is
- // shorter than it needs to be.
- cast::copy_lifetime(self, &bkt.value)
- };
- Some(ptr)
+ // FIXME(#3148)---should be inferred
+ let bkt: &self/Bucket<K,V> = bkt;
+ Some(&bkt.value)
}
None => {
fail ~"LinearMap::find: internal logic error"
View
23 src/libcore/str.rs
@@ -468,7 +468,7 @@ pure fn chars(s: &str) -> ~[char] {
let len = len(s);
while i < len {
let {ch, next} = char_range_at(s, i);
- unsafe { vec::push(buf, ch); }
+ unsafe { buf.push(ch); }
i = next;
}
move buf
@@ -537,8 +537,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
while i < l && done < count {
if s[i] == b {
if allow_empty || start < i unsafe {
- vec::push(result,
- unsafe { raw::slice_bytes(s, start, i) });
+ result.push(unsafe { raw::slice_bytes(s, start, i) });
}
start = i + 1u;
done += 1u;
@@ -546,7 +545,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
i += 1u;
}
if allow_empty || start < l {
- unsafe { vec::push(result, raw::slice_bytes(s, start, l) ) };
+ unsafe { result.push(raw::slice_bytes(s, start, l) ) };
}
move result
} else {
@@ -581,7 +580,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
let {ch, next} = char_range_at(s, i);
if sepfn(ch) {
if allow_empty || start < i unsafe {
- vec::push(result, unsafe { raw::slice_bytes(s, start, i)});
+ result.push(unsafe { raw::slice_bytes(s, start, i)});
}
start = next;
done += 1u;
@@ -589,7 +588,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
i = next;
}
if allow_empty || start < l unsafe {
- vec::push(result, unsafe { raw::slice_bytes(s, start, l) });
+ result.push(unsafe { raw::slice_bytes(s, start, l) });
}
move result
}
@@ -643,7 +642,7 @@ pure fn iter_between_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
pure fn split_str(s: &a/str, sep: &b/str) -> ~[~str] {
let mut result = ~[];
do iter_between_matches(s, sep) |from, to| {
- unsafe { vec::push(result, raw::slice_bytes(s, from, to)); }
+ unsafe { result.push(raw::slice_bytes(s, from, to)); }
}
move result
}
@@ -652,7 +651,7 @@ pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] {
let mut result = ~[];
do iter_between_matches(s, sep) |from, to| {
if to > from {
- unsafe { vec::push(result, raw::slice_bytes(s, from, to)); }
+ unsafe { result.push(raw::slice_bytes(s, from, to)); }
}
}
move result
@@ -1535,14 +1534,14 @@ pure fn to_utf16(s: &str) -> ~[u16] {
if (ch & 0xFFFF_u32) == ch unsafe {
// The BMP falls through (assuming non-surrogate, as it should)
assert ch <= 0xD7FF_u32 || ch >= 0xE000_u32;
- vec::push(u, ch as u16)
+ u.push(ch as u16)
} else unsafe {
// Supplementary planes break into surrogates.
assert ch >= 0x1_0000_u32 && ch <= 0x10_FFFF_u32;
ch -= 0x1_0000_u32;
let w1 = 0xD800_u16 | ((ch >> 10) as u16);
let w2 = 0xDC00_u16 | ((ch as u16) & 0x3FF_u16);
- vec::push_all(u, ~[w1, w2])
+ u.push_all(~[w1, w2])
}
}
move u
@@ -2010,7 +2009,7 @@ mod raw {
ptr::memcpy(vbuf, buf as *u8, len)
});
vec::raw::set_len(v, len);
- vec::push(v, 0u8);
+ v.push(0u8);
assert is_utf8(v);
return ::cast::transmute(move v);
@@ -2067,7 +2066,7 @@ mod raw {
ptr::memcpy(vbuf, src, end - begin);
}
vec::raw::set_len(v, end - begin);
- vec::push(v, 0u8);
+ v.push(0u8);
::cast::transmute(move v)
}
}
View
189 src/libcore/vec.rs
@@ -92,6 +92,8 @@ export CopyableVector;
export ImmutableVector;
export ImmutableEqVector;
export ImmutableCopyableVector;
+export MutableVector;
+export MutableCopyableVector;
export IterTraitExtensions;
export vec_concat;
export traits;
@@ -238,7 +240,7 @@ pure fn with_capacity<T>(capacity: uint) -> ~[T] {
pure fn build_sized<A>(size: uint,
builder: fn(push: pure fn(+v: A))) -> ~[A] {
let mut vec = with_capacity(size);
- builder(|+x| unsafe { push(vec, move x) });
+ builder(|+x| unsafe { vec.push(move x) });
move vec
}
@@ -330,7 +332,7 @@ pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
assert (end <= len(v));
let mut result = ~[];
unsafe {
- for uint::range(start, end) |i| { vec::push(result, v[i]) }
+ for uint::range(start, end) |i| { result.push(v[i]) }
}
move result
}
@@ -383,14 +385,14 @@ fn split<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let mut result = ~[];
while start < ln {
match position_between(v, start, ln, f) {
- None => break,
- Some(i) => {
- push(result, slice(v, start, i));
- start = i + 1u;
- }
+ None => break,
+ Some(i) => {
+ result.push(slice(v, start, i));
+ start = i + 1u;
+ }
}
}
- push(result, slice(v, start, ln));
+ result.push(slice(v, start, ln));
move result
}
@@ -407,16 +409,16 @@ fn splitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let mut result = ~[];
while start < ln && count > 0u {
match position_between(v, start, ln, f) {
- None => break,
- Some(i) => {
- push(result, slice(v, start, i));
- // Make sure to skip the separator.
- start = i + 1u;
- count -= 1u;
- }
+ None => break,
+ Some(i) => {
+ result.push(slice(v, start, i));
+ // Make sure to skip the separator.
+ start = i + 1u;
+ count -= 1u;
+ }
}
}
- push(result, slice(v, start, ln));
+ result.push(slice(v, start, ln));
move result
}
@@ -432,14 +434,14 @@ fn rsplit<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let mut result = ~[];
while end > 0u {
match rposition_between(v, 0u, end, f) {
- None => break,
- Some(i) => {
- push(result, slice(v, i + 1u, end));
- end = i;
- }
+ None => break,
+ Some(i) => {
+ result.push(slice(v, i + 1u, end));
+ end = i;
+ }
}
}
- push(result, slice(v, 0u, end));
+ result.push(slice(v, 0u, end));
reverse(result);
return move result;
}
@@ -457,16 +459,16 @@ fn rsplitn<T: Copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let mut result = ~[];
while end > 0u && count > 0u {
match rposition_between(v, 0u, end, f) {
- None => break,
- Some(i) => {
- push(result, slice(v, i + 1u, end));
- // Make sure to skip the separator.
- end = i;
- count -= 1u;
- }
+ None => break,
+ Some(i) => {
+ result.push(slice(v, i + 1u, end));
+ // Make sure to skip the separator.
+ end = i;
+ count -= 1u;
+ }
}
}
- push(result, slice(v, 0u, end));
+ result.push(slice(v, 0u, end));
reverse(result);
move result
}
@@ -489,7 +491,7 @@ fn shift<T>(&v: ~[T]) -> T {
for uint::range(1, ln) |i| {
let r <- *ptr::offset(vv, i);
- push(v, move r);
+ v.push(move r);
}
}
raw::set_len(vv, 0);
@@ -503,7 +505,7 @@ fn unshift<T>(&v: ~[T], +x: T) {
let mut vv = ~[move x];
v <-> vv;
while len(vv) > 0 {
- push(v, shift(vv));
+ v.push(shift(vv));
}
}
@@ -568,9 +570,9 @@ fn swap_remove<T>(&v: ~[const T], index: uint) -> T {
/// Append an element to a vector
#[inline(always)]
-fn push<T>(&v: ~[T], +initval: T) {
+fn push<T>(v: &mut ~[T], +initval: T) {
unsafe {
- let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v));
+ let repr: **raw::VecRepr = ::cast::transmute(copy v);
let fill = (**repr).unboxed.fill;
if (**repr).unboxed.alloc > fill {
push_fast(v, move initval);
@@ -583,8 +585,8 @@ fn push<T>(&v: ~[T], +initval: T) {
// This doesn't bother to make sure we have space.
#[inline(always)] // really pretty please
-unsafe fn push_fast<T>(&v: ~[T], +initval: T) {
- let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v));
+unsafe fn push_fast<T>(+v: &mut ~[T], +initval: T) {
+ let repr: **raw::VecRepr = ::cast::transmute(v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
let p = ptr::addr_of((**repr).unboxed.data);
@@ -593,14 +595,14 @@ unsafe fn push_fast<T>(&v: ~[T], +initval: T) {
}
#[inline(never)]
-fn push_slow<T>(&v: ~[T], +initval: T) {
- reserve_at_least(&mut v, v.len() + 1u);
+fn push_slow<T>(+v: &mut ~[T], +initval: T) {
+ reserve_at_least(v, v.len() + 1u);
unsafe { push_fast(v, move initval) }
}
#[inline(always)]
-fn push_all<T: Copy>(&v: ~[T], rhs: &[const T]) {
- reserve(&mut v, v.len() + rhs.len());
+fn push_all<T: Copy>(+v: &mut ~[T], rhs: &[const T]) {
+ reserve(v, v.len() + rhs.len());
for uint::range(0u, rhs.len()) |i| {
push(v, unsafe { raw::get(rhs, i) })
@@ -608,8 +610,8 @@ fn push_all<T: Copy>(&v: ~[T], rhs: &[const T]) {
}
#[inline(always)]
-fn push_all_move<T>(&v: ~[T], -rhs: ~[const T]) {
- reserve(&mut v, v.len() + rhs.len());
+fn push_all_move<T>(v: &mut ~[T], -rhs: ~[const T]) {
+ reserve(v, v.len() + rhs.len());
unsafe {
do as_imm_buf(rhs) |p, len| {
for uint::range(0, len) |i| {
@@ -675,7 +677,7 @@ fn dedup<T: Eq>(&v: ~[const T]) unsafe {
pure fn append<T: Copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
let mut v <- lhs;
unsafe {
- push_all(v, rhs);
+ v.push_all(rhs);
}
move v
}
@@ -683,7 +685,7 @@ pure fn append<T: Copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
#[inline(always)]
pure fn append_one<T>(+lhs: ~[T], +x: T) -> ~[T] {
let mut v <- lhs;
- unsafe { push(v, move x); }
+ unsafe { v.push(move x); }
move v
}
@@ -705,7 +707,10 @@ fn grow<T: Copy>(&v: ~[T], n: uint, initval: T) {
reserve_at_least(&mut v, len(v) + n);
let mut i: uint = 0u;
- while i < n { push(v, initval); i += 1u; }
+ while i < n {
+ v.push(initval);
+ i += 1u;
+ }
}
/**
@@ -724,7 +729,10 @@ fn grow<T: Copy>(&v: ~[T], n: uint, initval: T) {
fn grow_fn<T>(&v: ~[T], n: uint, op: iter::InitOp<T>) {
reserve_at_least(&mut v, len(v) + n);
let mut i: uint = 0u;
- while i < n { push(v, op(i)); i += 1u; }
+ while i < n {
+ v.push(op(i));
+ i += 1u;
+ }
}
/**
@@ -745,14 +753,18 @@ fn grow_set<T: Copy>(&v: ~[T], index: uint, initval: T, val: T) {
/// Apply a function to each element of a vector and return the results
pure fn map<T, U>(v: &[T], f: fn(v: &T) -> U) -> ~[U] {
let mut result = with_capacity(len(v));
- for each(v) |elem| { unsafe { push(result, f(elem)); } }
+ for each(v) |elem| {
+ unsafe {
+ result.push(f(elem));
+ }
+ }
move result
}
fn map_consume<T, U>(+v: ~[T], f: fn(+v: T) -> U) -> ~[U] {
let mut result = ~[];
do consume(move v) |_i, x| {
- vec::push(result, f(move x));
+ result.push(f(move x));
}
move result
}
@@ -772,7 +784,7 @@ pure fn mapi<T, U>(v: &[T], f: fn(uint, v: &T) -> U) -> ~[U] {
*/
pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] {
let mut result = ~[];
- for each(v) |elem| { unsafe{ push_all_move(result, f(*elem)); } }
+ for each(v) |elem| { unsafe{ result.push_all_move(f(*elem)); } }
move result
}
@@ -784,7 +796,7 @@ pure fn map2<T: Copy, U: Copy, V>(v0: &[T], v1: &[U],
let mut u: ~[V] = ~[];
let mut i = 0u;
while i < v0_len {
- unsafe { push(u, f(copy v0[i], copy v1[i])) };
+ unsafe { u.push(f(copy v0[i], copy v1[i])) };
i += 1u;
}
move u
@@ -802,7 +814,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
for each(v) |elem| {
match f(*elem) {
None => {/* no-op */ }
- Some(result_elem) => unsafe { push(result, result_elem); }
+ Some(result_elem) => unsafe { result.push(result_elem); }
}
}
move result
@@ -818,7 +830,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(T) -> Option<U>)
pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
let mut result = ~[];
for each(v) |elem| {
- if f(*elem) { unsafe { push(result, *elem); } }
+ if f(*elem) { unsafe { result.push(*elem); } }
}
move result
}
@@ -830,7 +842,7 @@ pure fn filter<T: Copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
*/
pure fn concat<T: Copy>(v: &[~[T]]) -> ~[T] {
let mut r = ~[];
- for each(v) |inner| { unsafe { push_all(r, *inner); } }
+ for each(v) |inner| { unsafe { r.push_all(*inner); } }
move r
}
@@ -839,8 +851,8 @@ pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
let mut r: ~[T] = ~[];
let mut first = true;
for each(v) |inner| {
- if first { first = false; } else { unsafe { push(r, sep); } }
- unsafe { push_all(r, *inner) };
+ if first { first = false; } else { unsafe { r.push(sep); } }
+ unsafe { r.push_all(*inner) };
}
move r
}
@@ -1059,15 +1071,15 @@ pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
*/
pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
- let mut as_ = ~[], bs = ~[];
+ let mut ts = ~[], us = ~[];
for each(v) |p| {
- let (a, b) = *p;
+ let (t, u) = *p;
unsafe {
- vec::push(as_, a);
- vec::push(bs, b);
+ ts.push(t);
+ us.push(u);
}
}
- return (move as_, move bs);
+ return (move ts, move us);
}
/**
@@ -1082,9 +1094,9 @@ pure fn unzip<T,U>(+v: ~[(T, U)]) -> (~[T], ~[U]) {
let mut ts = ~[], us = ~[];
unsafe {
do consume(move v) |_i, p| {
- let (a,b) = move p;
- push(ts, move a);
- push(us, move b);
+ let (t, u) = move p;
+ ts.push(move t);
+ us.push(move u);
}
}
(move ts, move us)
@@ -1099,7 +1111,7 @@ pure fn zip_slice<T: Copy, U: Copy>(v: &[const T], u: &[const U])
let sz = len(v);
let mut i = 0u;
assert sz == len(u);
- while i < sz unsafe { vec::push(zipped, (v[i], u[i])); i += 1u; }
+ while i < sz unsafe { zipped.push((v[i], u[i])); i += 1u; }
move zipped
}
@@ -1114,7 +1126,7 @@ pure fn zip<T, U>(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] {
assert i == len(u);
let mut w = with_capacity(i);
while i > 0 {
- unsafe { push(w, (pop(v),pop(u))); }
+ unsafe { w.push((pop(v),pop(u))); }
i -= 1;
}
unsafe { reverse(w); }
@@ -1147,8 +1159,8 @@ pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
let mut i = len::<T>(v);
if i == 0 { return (move rs); } else { i -= 1; }
unsafe {
- while i != 0 { vec::push(rs, v[i]); i -= 1; }
- vec::push(rs, v[0]);
+ while i != 0 { rs.push(v[i]); i -= 1; }
+ rs.push(v[0]);
}
move rs
}
@@ -1283,7 +1295,7 @@ pure fn permute<T: Copy>(v: &[const T], put: fn(~[T])) {
let elt = v[i];
let mut rest = slice(v, 0u, i);
unsafe {
- push_all(rest, const_view(v, i+1u, ln));
+ rest.push_all(const_view(v, i+1u, ln));
permute(rest, |permutation| {
put(append(~[elt], permutation))
})
@@ -1299,7 +1311,7 @@ pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
for vec::eachi (xx) |ii, _x| {
let len = vec::len(xx);
if ii+nn <= len unsafe {
- vec::push(ww, vec::slice(xx, ii, ii+nn));
+ ww.push(vec::slice(xx, ii, ii+nn));
}
}
move ww
@@ -1551,7 +1563,7 @@ impl<T> &[T]: ImmutableVector<T> {
let mut r = ~[];
let mut i = 0;
while i < self.len() {
- push(r, f(&self[i]));
+ r.push(f(&self[i]));
i += 1;
}
move r
@@ -1637,6 +1649,31 @@ impl<T: Copy> &[T]: ImmutableCopyableVector<T> {
pure fn rfind(f: fn(T) -> bool) -> Option<T> { rfind(self, f) }
}
+trait MutableVector<T> {
+ fn push(&mut self, +t: T);
+ fn push_all_move(&mut self, -rhs: ~[const T]);
+}
+
+trait MutableCopyableVector<T: Copy> {
+ fn push_all(&mut self, rhs: &[const T]);
+}
+
+impl<T> ~[T]: MutableVector<T> {
+ fn push(&mut self, +t: T) {
+ push(self, move t);
+ }
+
+ fn push_all_move(&mut self, -rhs: ~[const T]) {
+ push_all_move(self, move rhs);
+ }
+}
+
+impl<T: Copy> ~[T]: MutableCopyableVector<T> {
+ fn push_all(&mut self, rhs: &[const T]) {
+ push_all(self, rhs);
+ }
+}
+
/// Unsafe operations
mod raw {
#[legacy_exports];
@@ -2109,12 +2146,12 @@ mod tests {
fn test_push() {
// Test on-stack push().
let mut v = ~[];
- push(v, 1);
+ v.push(1);
assert (len(v) == 1u);
assert (v[0] == 1);
// Test on-heap push().
- push(v, 2);
+ v.push(2);
assert (len(v) == 2u);
assert (v[0] == 1);
assert (v[1] == 2);
@@ -2380,19 +2417,19 @@ mod tests {
let mut results: ~[~[int]];
results = ~[];
- permute(~[], |v| vec::push(results, copy v));
+ permute(~[], |v| results.push(copy v));
assert results == ~[~[]];
results = ~[];
- permute(~[7], |v| push(results, copy v));
+ permute(~[7], |v| results.push(copy v));
assert results == ~[~[7]];
results = ~[];
- permute(~[1,1], |v| push(results, copy v));
+ permute(~[1,1], |v| results.push(copy v));
assert results == ~[~[1,1],~[1,1]];
results = ~[];
- permute(~[5,2,0], |v| push(results, copy v));
+ permute(~[5,2,0], |v| results.push(copy v));
assert results ==
~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]];
}
View
4 src/libstd/arc.rs
@@ -648,7 +648,7 @@ mod tests {
let mut children = ~[];
for 5.times {
let arc3 = ~arc.clone();
- do task::task().future_result(|+r| vec::push(children, r)).spawn {
+ do task::task().future_result(|+r| children.push(r)).spawn {
do arc3.read |num| {
assert *num >= 0;
}
@@ -676,7 +676,7 @@ mod tests {
let mut reader_convos = ~[];
for 10.times {
let ((rc1,rp1),(rc2,rp2)) = (pipes::stream(),pipes::stream());
- vec::push(reader_convos, (rc1,rp2));
+ reader_convos.push((rc1,rp2));
let arcn = ~arc.clone();
do task::spawn {
rp1.recv(); // wait for downgrader to give go-ahead
View
12 src/libstd/base64.rs
@@ -102,12 +102,12 @@ impl ~[u8]: FromBase64 {
} else if ch == '=' {
match len - i {
1u => {
- vec::push(r, ((n >> 16u) & 0xFFu) as u8);
- vec::push(r, ((n >> 8u ) & 0xFFu) as u8);
+ r.push(((n >> 16u) & 0xFFu) as u8);
+ r.push(((n >> 8u ) & 0xFFu) as u8);
return copy r;
}
2u => {
- vec::push(r, ((n >> 10u) & 0xFFu) as u8);
+ r.push(((n >> 10u) & 0xFFu) as u8);
return copy r;
}
_ => fail ~"invalid base64 padding"
@@ -119,9 +119,9 @@ impl ~[u8]: FromBase64 {
i += 1u;
};
- vec::push(r, ((n >> 16u) & 0xFFu) as u8);
- vec::push(r, ((n >> 8u ) & 0xFFu) as u8);
- vec::push(r, ((n ) & 0xFFu) as u8);
+ r.push(((n >> 16u) & 0xFFu) as u8);
+ r.push(((n >> 8u ) & 0xFFu) as u8);
+ r.push(((n ) & 0xFFu) as u8);
}
r
View
4 src/libstd/deque.rs
@@ -38,8 +38,8 @@ fn create<T: Copy>() -> Deque<T> {
let nalloc = uint::next_power_of_two(nelts + 1u);
while i < nalloc {
if i < nelts {
- vec::push(rv, elts[(lo + i) % nelts]);
- } else { vec::push(rv, None); }
+ rv.push(elts[(lo + i) % nelts]);
+ } else { rv.push(None); }
i += 1u;
}
View
2  src/libstd/ebml.rs
@@ -211,7 +211,7 @@ impl Writer {
write_vuint(self.writer, tag_id);
// Write a placeholder four-byte size.
- vec::push(self.size_positions, self.writer.tell());
+ self.size_positions.push(self.writer.tell());
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
self.writer.write(zeroes);
}
View
2  src/libstd/ebml2.rs
@@ -220,7 +220,7 @@ impl Serializer {
write_vuint(self.writer, tag_id);
// Write a placeholder four-byte size.
- vec::push(self.size_positions, self.writer.tell());
+ self.size_positions.push(self.writer.tell());
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
self.writer.write(zeroes);
}
View
21 src/libstd/getopts.rs
@@ -234,10 +234,10 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
let cur = args[i];
let curlen = str::len(cur);
if !is_arg(cur) {
- vec::push(free, cur);
+ free.push(cur);
} else if cur == ~"--" {
let mut j = i + 1u;
- while j < l { vec::push(free, args[j]); j += 1u; }
+ while j < l { free.push(args[j]); j += 1u; }
break;
} else {
let mut names;
@@ -287,7 +287,7 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
}
}
}
- vec::push(names, opt);
+ names.push(opt);
j = range.next;
}
}
@@ -303,23 +303,22 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
if !i_arg.is_none() {
return Err(UnexpectedArgument(name_str(nm)));
}
- vec::push(vals[optid], Given);
+ vals[optid].push(Given);
}
Maybe => {
if !i_arg.is_none() {
- vec::push(vals[optid], Val(i_arg.get()));
+ vals[optid].push(Val(i_arg.get()));
} else if name_pos < vec::len::<Name>(names) ||
i + 1u == l || is_arg(args[i + 1u]) {
- vec::push(vals[optid], Given);
- } else { i += 1u; vec::push(vals[optid], Val(args[i])); }
+ vals[optid].push(Given);
+ } else { i += 1u; vals[optid].push(Val(args[i])); }
}
Yes => {
if !i_arg.is_none() {
- vec::push(vals[optid],
- Val(i_arg.get()));
+ vals[optid].push(Val(i_arg.get()));
} else if i + 1u == l {
return Err(ArgumentMissing(name_str(nm)));
- } else { i += 1u; vec::push(vals[optid], Val(args[i])); }
+ } else { i += 1u; vals[optid].push(Val(args[i])); }
}
}
}
@@ -412,7 +411,7 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(mm, nm)) |v| {
- match *v { Val(s) => vec::push(acc, s), _ => () }
+ match *v { Val(s) => acc.push(s), _ => () }
}
return acc;
}
View
29 src/libstd/json.rs
@@ -594,7 +594,7 @@ priv impl Parser {
loop {
match move self.parse_value() {
- Ok(move v) => vec::push(values, v),
+ Ok(move v) => values.push(v),
Err(move e) => return Err(e)
}
@@ -690,13 +690,13 @@ pub fn Deserializer(rdr: io::Reader) -> Result<Deserializer, Error> {
}
priv impl Deserializer {
- fn peek() -> &self/Json {
- if self.stack.len() == 0 { vec::push(self.stack, &self.json); }
+ fn peek(&self) -> &self/Json {
+ if self.stack.len() == 0 { self.stack.push(&self.json); }
vec::last(self.stack)
}
- fn pop() -> &self/Json {
- if self.stack.len() == 0 { vec::push(self.stack, &self.json); }
+ fn pop(&self) -> &self/Json {
+ if self.stack.len() == 0 { self.stack.push(&self.json); }
vec::pop(self.stack)
}
}
@@ -772,7 +772,7 @@ pub impl Deserializer: serialization2::Deserializer {
fn read_vec<T>(&self, f: fn(uint) -> T) -> T {
debug!("read_vec()");
let len = match *self.peek() {
- List(list) => list.len(),
+ List(ref list) => list.len(),
_ => fail ~"not a list",
};
let res = f(len);
@@ -784,7 +784,10 @@ pub impl Deserializer: serialization2::Deserializer {
debug!("read_vec_elt(idx=%u)", idx);
match *self.peek() {
List(ref list) => {
- vec::push(self.stack, &list[idx]);
+ // FIXME(#3148)---should be inferred
+ let list: &self/~[Json] = list;
+
+ self.stack.push(&list[idx]);
f()
}
_ => fail ~"not a list",
@@ -820,7 +823,7 @@ pub impl Deserializer: serialization2::Deserializer {
match obj.find_ref(&f_name) {
None => fail fmt!("no such field: %s", f_name),
Some(json) => {
- vec::push(self.stack, json);
+ self.stack.push(json);
f()
}
}
@@ -845,8 +848,10 @@ pub impl Deserializer: serialization2::Deserializer {
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
debug!("read_tup_elt(idx=%u)", idx);
match *self.peek() {
- List(list) => {
- vec::push(self.stack, &list[idx]);
+ List(ref list) => {
+ // FIXME(#3148)---should be inferred
+ let list: &self/~[Json] = list;
+ self.stack.push(&list[idx]);
f()
}
_ => fail ~"not a list"
@@ -939,12 +944,12 @@ impl Json : Ord {
// XXX: this is horribly inefficient...
for d0.each |k, v| {
- vec::push(d0_flat, (@copy *k, @copy *v));
+ d0_flat.push((@copy *k, @copy *v));
}
d0_flat.qsort();
for d1.each |k, v| {
- vec::push(d1_flat, (@copy *k, @copy *v));
+ d1_flat.push((@copy *k, @copy *v));
}
d1_flat.qsort();
View
4 src/libstd/md4.rs
@@ -11,14 +11,14 @@ fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
let mut msg = vec::append(vec::from_slice(msg), ~[0x80u8]);
let mut bitlen = orig_len + 8u64;
while (bitlen + 64u64) % 512u64 > 0u64 {
- vec::push(msg, 0u8);
+ msg.push(0u8);
bitlen += 8u64;
}
// append length
let mut i = 0u64;
while i < 8u64 {
- vec::push(msg, (orig_len >> (i * 8u64)) as u8);
+ msg.push((orig_len >> (i * 8u64)) as u8);
i += 1u64;
}
View
2  src/libstd/net_ip.rs
@@ -277,7 +277,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
result::Err(GetAddrUnknownError));
break;
};
- vec::push(out_vec, move new_ip_addr);
+ out_vec.push(move new_ip_addr);
let next_addr = ll::get_next_addrinfo(curr_addr);
if next_addr == ptr::null::<addrinfo>() as *addrinfo {
View
4 src/libstd/net_tcp.rs
@@ -779,7 +779,7 @@ impl TcpSocketBuf: io::Reader {
}
}
else {
- vec::push_all(self.data.buf, result::unwrap(read_result));
+ self.data.buf.push_all(result::unwrap(read_result));
}
}
@@ -790,7 +790,7 @@ impl TcpSocketBuf: io::Reader {
vec::bytes::memcpy(buf, vec::view(data, 0, data.len()), count);
- vec::push_all(self.data.buf, vec::view(data, count, data.len()));
+ self.data.buf.push_all(vec::view(data, count, data.len()));
count
}
View
2  src/libstd/net_url.rs
@@ -329,7 +329,7 @@ fn query_from_str(rawquery: &str) -> Query {
if str::len(rawquery) != 0 {
for str::split_char(rawquery, '&').each |p| {
let (k, v) = split_char_first(*p, '=');
- vec::push(query, (decode_component(k), decode_component(v)));
+ query.push((decode_component(k), decode_component(v)));
};
}
return query;
View
2  src/libstd/par.rs
@@ -55,7 +55,7 @@ fn map_slices<A: Copy Send, B: Copy Send>(
f(base, slice)
}
};
- vec::push(futures, move f);
+ futures.push(move f);
};
base += items_per_task;
}
View
2  src/libstd/rope.rs
@@ -869,7 +869,7 @@ mod node {
loop {
match (leaf_iterator::next(&it)) {
option::None => break,
- option::Some(x) => vec::push(forest, @Leaf(x))
+ option::Some(x) => forest.push(@Leaf(x))
}
}
//2. Rebuild tree from forest
View
4 src/libstd/sort.rs
@@ -47,9 +47,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]) {
- vec::push(rs, a[a_ix]);
+ rs.push(a[a_ix]);
a_ix += 1u;
- } else { vec::push(rs, b[b_ix]); b_ix += 1u; }
+ } else { rs.push(b[b_ix]); b_ix += 1u; }
}
rs = vec::append(rs, vec::slice(a, a_ix, a_len));
rs = vec::append(rs, vec::slice(b, b_ix, b_len));
View
8 src/libstd/sync.rs
@@ -82,7 +82,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint)
-> Sem<~[mut Waitqueue]> {
let mut queues = ~[];
for num_condvars.times {
- vec::push(queues, new_waitqueue());
+ queues.push(new_waitqueue());
}
new_sem(count, vec::to_mut(move queues))
}
@@ -840,7 +840,7 @@ mod tests {
for num_waiters.times {
let mi = ~m.clone();
let (chan, port) = pipes::stream();
- vec::push(ports, port);
+ ports.push(port);
do task::spawn {
do mi.lock_cond |cond| {
chan.send(());
@@ -930,7 +930,7 @@ mod tests {
for 2.times {
let (c,p) = pipes::stream();
let c = ~mut Some(c);
- vec::push(sibling_convos, p);
+ sibling_convos.push(p);
let mi = ~m2.clone();
// spawn sibling task
do task::spawn { // linked
@@ -1194,7 +1194,7 @@ mod tests {
for num_waiters.times {
let xi = ~x.clone();
let (chan, port) = pipes::stream();
- vec::push(ports, port);
+ ports.push(port);
do task::spawn {
do lock_cond(xi, dg1) |cond| {
chan.send(());
View
4 src/libstd/test.rs
@@ -141,7 +141,7 @@ fn run_tests_console(opts: &TestOpts,
st.failed += 1u;
write_failed(st.out, st.use_color);
st.out.write_line(~"");
- vec::push(st.failures, copy test);
+ st.failures.push(copy test);
}
TrIgnored => {
st.ignored += 1u;
@@ -545,7 +545,7 @@ mod tests {
for vec::each(names) |name| {
let test = {name: *name, testfn: copy testfn, ignore: false,
should_fail: false};
- vec::push(tests, test);
+ tests.push(test);
}
tests
};
View
4 src/libsyntax/ast_map.rs
@@ -273,9 +273,9 @@ fn map_item(i: @item, cx: ctx, v: vt) {
}
match i.node {
item_mod(_) | item_foreign_mod(_) => {
- vec::push(cx.path, path_mod(i.ident));
+ cx.path.push(path_mod(i.ident));
}
- _ => vec::push(cx.path, path_name(i.ident))
+ _ => cx.path.push(path_name(i.ident))
}
visit::visit_item(i, cx, v);
vec::pop(cx.path);
View
4 src/libsyntax/ast_util.rs
@@ -313,8 +313,8 @@ fn split_trait_methods(trait_methods: ~[trait_method])
let mut reqd = ~[], provd = ~[];
for trait_methods.each |trt_method| {
match *trt_method {
- required(tm) => vec::push(reqd, tm),
- provided(m) => vec::push(provd, m)
+ required(tm) => reqd.push(tm),
+ provided(m) => provd.push(m)
}
};
(reqd, provd)
View
2  src/libsyntax/attr.rs