Skip to content

Commit 67a8e71

Browse files
committed
Demode vec::push (and convert to method)
1 parent cd79e1d commit 67a8e71

File tree

134 files changed

+684
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+684
-670
lines changed

doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ fn iter<T>(seq: ~[T], f: fn(T)) {
10161016
}
10171017
fn map<T, U>(seq: ~[T], f: fn(T) -> U) -> ~[U] {
10181018
let mut acc = ~[];
1019-
for seq.each |elt| { vec::push(acc, f(elt)); }
1019+
for seq.each |elt| { acc.push(f(elt)); }
10201020
acc
10211021
}
10221022
~~~~

doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ may be invoked on multiple types.
16511651
fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
16521652
let mut accumulator = ~[];
16531653
for vec::each(vector) |element| {
1654-
vec::push(accumulator, function(element));
1654+
accumulator.push(function(element));
16551655
}
16561656
return accumulator;
16571657
}

src/cargo/cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn load_crate(filename: &Path) -> Option<Crate> {
345345

346346
match *ps.interner.get(attr_name) {
347347
~"std" | ~"core" => (),
348-
_ => vec::push(e.deps, query)
348+
_ => e.deps.push(query)
349349
}
350350
}
351351
_ => ()
@@ -801,7 +801,7 @@ fn install_source(c: &Cargo, path: &Path) {
801801
let mut cratefiles = ~[];
802802
for os::walk_dir(&Path(".")) |p| {
803803
if p.filetype() == Some(~".rc") {
804-
vec::push(cratefiles, *p);
804+
cratefiles.push(*p);
805805
}
806806
}
807807

src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn make_tests(config: config) -> ~[test::TestDesc] {
141141
let file = copy *file;
142142
debug!("inspecting file %s", file.to_str());
143143
if is_test(config, file) {
144-
vec::push(tests, make_test(config, file))
144+
tests.push(make_test(config, file))
145145
}
146146
}
147147
return tests;

src/compiletest/header.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn load_props(testfile: &Path) -> test_props {
2828
let mut pp_exact = option::None;
2929
for iter_header(testfile) |ln| {
3030
match parse_error_pattern(ln) {
31-
option::Some(ep) => vec::push(error_patterns, ep),
31+
option::Some(ep) => error_patterns.push(ep),
3232
option::None => ()
3333
};
3434

@@ -41,11 +41,11 @@ fn load_props(testfile: &Path) -> test_props {
4141
}
4242

4343
do parse_aux_build(ln).iter |ab| {
44-
vec::push(aux_builds, ab);
44+
aux_builds.push(ab);
4545
}
4646

4747
do parse_exec_env(ln).iter |ee| {
48-
vec::push(exec_env, ee);
48+
exec_env.push(ee);
4949
}
5050
};
5151
return {

src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
1919
else { (k,v) }
2020
};
2121
if str::ends_with(prog, ~"rustc.exe") {
22-
vec::push(env, (~"RUST_THREADS", ~"1"));
22+
env.push((~"RUST_THREADS", ~"1"));
2323
}
2424
return env;
2525
}

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
121121
procres);
122122
}
123123

124-
vec::push(srcs, procres.stdout);
124+
srcs.push(procres.stdout);
125125
round += 1;
126126
}
127127

src/fuzzer/cycles.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn test_cycles(r : rand::rng, k: uint, n: uint)
6262

6363
// Create a graph with no edges
6464
range(0u, vlen) {|_i|
65-
vec::push(v, empty_pointy());
65+
v.push(empty_pointy());
6666
}
6767

6868
// 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)
7777
// https://github.com/mozilla/rust/issues/1899
7878

7979
if (likelihood(r, k, n)) { v[i].m = [p(choice(r, v))]; }
80-
if (likelihood(r, k, n)) { vec::push(v[i].n, mut p(choice(r, v))); }
80+
if (likelihood(r, k, n)) { v[i].n.push(mut p(choice(r, v))); }
8181
if (likelihood(r, k, n)) { v[i].o = {x: 0, y: p(choice(r, v))}; }
8282
}
8383

src/fuzzer/fuzzer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn contains(haystack: ~str, needle: ~str) -> bool {
3030
fn find_rust_files(files: &mut ~[Path], path: &Path) {
3131
if path.filetype() == Some(~".rs") && !contains(path.to_str(), ~"utf8") {
3232
// ignoring "utf8" tests because something is broken
33-
vec::push(*files, *path);
33+
files.push(*path);
3434
} else if os::path_is_dir(path)
3535
&& !contains(path.to_str(), ~"compile-fail")
3636
&& !contains(path.to_str(), ~"build") {
@@ -124,7 +124,7 @@ fn stash_ty_if(c: fn@(@ast::ty, test_mode)->bool,
124124
e: @ast::ty,
125125
tm: test_mode) {
126126
if c(e, tm) {
127-
vec::push(*es,*e);
127+
es.push(e);
128128
} else {/* now my indices are wrong :( */ }
129129
}
130130

src/fuzzer/ivec_fuzz.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ fn vec_edits<T: copy>(v: ~[T], xs: ~[T]) -> ~[~[T]] {
5555

5656
if Lv != 1u {
5757
// When Lv == 1u, this is redundant with omit.
58-
vec::push(edits, ~[]);
58+
edits.push(~[]);
5959
}
6060
if Lv >= 3u {
6161
// When Lv == 2u, this is redundant with swap.
62-
vec::push(edits, vec::reversed(v));
62+
edits.push(vec::reversed(v));
6363
}
6464
ix(0u, 1u, Lv) {|i| edits += ~[vec_omit(v, i)]; }
6565
ix(0u, 1u, Lv) {|i| edits += ~[vec_dup(v, i)]; }
@@ -69,10 +69,10 @@ fn vec_edits<T: copy>(v: ~[T], xs: ~[T]) -> ~[~[T]] {
6969

7070
ix(0u, 1u, len(xs)) {|j|
7171
ix(0u, 1u, Lv) {|i|
72-
vec::push(edits, vec_poke(v, i, xs[j]));
72+
edits.push(vec_poke(v, i, xs[j]));
7373
}
7474
ix(0u, 0u, Lv) {|i|
75-
vec::push(edits, vec_insert(v, i, xs[j]));
75+
edits.push(vec_insert(v, i, xs[j]));
7676
}
7777
}
7878

src/fuzzer/rand_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn weighted_vec<T: copy>(v : ~[weighted<T>]) -> ~[T] {
6161
for {weight: weight, item: item} in v {
6262
let i = 0u;
6363
while i < weight {
64-
vec::push(r, item);
64+
r.push(item);
6565
i += 1u;
6666
}
6767
}

src/libcore/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tuple::{TupleOps, ExtendedTupleOps};
1717
use str::{StrSlice, UniqueStr};
1818
use vec::{ConstVector, CopyableVector, ImmutableVector};
1919
use vec::{ImmutableEqVector, ImmutableCopyableVector};
20+
use vec::{MutableVector, MutableCopyableVector};
2021
use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
2122
use iter::{CopyableOrderedIter, Times, TimesIx};
2223
use num::Num;
@@ -33,6 +34,7 @@ export Num, Times, TimesIx;
3334
export StrSlice, UniqueStr;
3435
export ConstVector, CopyableVector, ImmutableVector;
3536
export ImmutableEqVector, ImmutableCopyableVector, IterTraitExtensions;
37+
export MutableVector, MutableCopyableVector;
3638
export BaseIter, CopyableIter, CopyableOrderedIter, ExtendedIter, EqIter;
3739
export TupleOps, ExtendedTupleOps;
3840
export Ptr;

src/libcore/dvec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ impl<A> DVec<A> {
172172
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
173173
log(error, ~"a");
174174
self.data <- ~[move t];
175-
vec::push_all_move(self.data, move data);
175+
self.data.push_all_move(move data);
176176
log(error, ~"b");
177177
}
178178
}
179179
180180
/// Append a single item to the end of the list
181181
fn push(+t: A) {
182182
self.check_not_borrowed();
183-
vec::push(self.data, move t);
183+
self.data.push(move t);
184184
}
185185
186186
/// Remove and return the first element
@@ -240,7 +240,7 @@ impl<A: Copy> DVec<A> {
240240
vec::reserve(&mut v, new_len);
241241
let mut i = from_idx;
242242
while i < to_idx {
243-
vec::push(v, ts[i]);
243+
v.push(ts[i]);
244244
i += 1u;
245245
}
246246
move v
@@ -266,7 +266,7 @@ impl<A: Copy> DVec<A> {
266266
}
267267
};
268268
269-
for ts.each |t| { vec::push(v, *t) };
269+
for ts.each |t| { v.push(*t) };
270270
v
271271
}
272272
}

src/libcore/either.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ fn either<T, U, V>(f_left: fn((&T)) -> V,
3232
fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
3333
//! Extracts from a vector of either all the left values
3434
35-
let mut result: ~[T] = ~[];
36-
for vec::each(eithers) |elt| {
37-
match *elt {
38-
Left(l) => vec::push(result, l),
39-
_ => { /* fallthrough */ }
35+
do vec::build_sized(eithers.len()) |push| {
36+
for vec::each(eithers) |elt| {
37+
match *elt {
38+
Left(ref l) => { push(*l); }
39+
_ => { /* fallthrough */ }
40+
}
4041
}
4142
}
42-
move result
4343
}
4444

4545
fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
4646
//! Extracts from a vector of either all the right values
4747
48-
let mut result: ~[U] = ~[];
49-
for vec::each(eithers) |elt| {
50-
match *elt {
51-
Right(r) => vec::push(result, r),
52-
_ => { /* fallthrough */ }
48+
do vec::build_sized(eithers.len()) |push| {
49+
for vec::each(eithers) |elt| {
50+
match *elt {
51+
Right(ref r) => { push(*r); }
52+
_ => { /* fallthrough */ }
53+
}
5354
}
5455
}
55-
move result
5656
}
5757

5858
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
@@ -68,8 +68,8 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
6868
let mut rights: ~[U] = ~[];
6969
for vec::each(eithers) |elt| {
7070
match *elt {
71-
Left(l) => vec::push(lefts, l),
72-
Right(r) => vec::push(rights, r)
71+
Left(l) => lefts.push(l),
72+
Right(r) => rights.push(r)
7373
}
7474
}
7575
return {lefts: move lefts, rights: move rights};

src/libcore/extfmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ mod ct {
9090
fn flush_buf(+buf: ~str, &pieces: ~[Piece]) -> ~str {
9191
if str::len(buf) > 0 {
9292
let piece = PieceString(move buf);
93-
vec::push(pieces, move piece);
93+
pieces.push(move piece);
9494
}
9595
return ~"";
9696
}
@@ -110,7 +110,7 @@ mod ct {
110110
} else {
111111
buf = flush_buf(move buf, pieces);
112112
let rs = parse_conversion(s, i, lim, error);
113-
vec::push(pieces, copy rs.piece);
113+
pieces.push(copy rs.piece);
114114
i = rs.next;
115115
}
116116
} else { buf += curr; i += size; }

src/libcore/flate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ fn test_flate_round_trip() {
7171
let r = rand::Rng();
7272
let mut words = ~[];
7373
for 20.times {
74-
vec::push(words, r.gen_bytes(r.gen_uint_range(1, 10)));
74+
words.push(r.gen_bytes(r.gen_uint_range(1, 10)));
7575
}
7676
for 20.times {
7777
let mut in = ~[];
7878
for 2000.times {
79-
vec::push_all(in, r.choose(words));
79+
in.push_all(r.choose(words));
8080
}
8181
debug!("de/inflate of %u bytes of random word-sequences",
8282
in.len());

src/libcore/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
143143
// store the next digit
144144
frac *= 10.0;
145145
let digit = frac as uint;
146-
vec::push(fractionalParts, digit);
146+
fractionalParts.push(digit);
147147

148148
// calculate the next frac
149149
frac -= digit as float;

src/libcore/io.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<T: Reader> T : ReaderUtil {
7676
loop {
7777
let ch = self.read_byte();
7878
if ch == -1 || ch == 10 { break; }
79-
vec::push(buf, ch as u8);
79+
buf.push(ch as u8);
8080
}
8181
str::from_bytes(buf)
8282
}
@@ -94,7 +94,7 @@ impl<T: Reader> T : ReaderUtil {
9494
i += 1;
9595
assert (w > 0);
9696
if w == 1 {
97-
vec::push(*chars, b0 as char);
97+
chars.push(b0 as char);
9898
loop;
9999
}
100100
// can't satisfy this char with the existing data
@@ -113,7 +113,7 @@ impl<T: Reader> T : ReaderUtil {
113113
// See str::char_at
114114
val += ((b0 << ((w + 1) as u8)) as uint)
115115
<< (w - 1) * 6 - w - 1u;
116-
vec::push(*chars, val as char);
116+
chars.push(val as char);
117117
}
118118
return (i, 0);
119119
}
@@ -128,7 +128,7 @@ impl<T: Reader> T : ReaderUtil {
128128
// we're split in a unicode char?
129129
break;
130130
}
131-
vec::push_all(buf, data);
131+
buf.push_all(data);
132132
let (offset, nbreq) = chars_from_bytes::<T>(&buf, &mut chars);
133133
let ncreq = n - chars.len();
134134
// again we either know we need a certain number of bytes
@@ -155,7 +155,7 @@ impl<T: Reader> T : ReaderUtil {
155155
let mut buf: ~[u8] = ~[];
156156
loop {
157157
let ch = self.read_byte();
158-
if ch < 1 { break; } else { vec::push(buf, ch as u8); }
158+
if ch < 1 { break; } else { buf.push(ch as u8); }
159159
}
160160
str::from_bytes(buf)
161161
}
@@ -190,7 +190,7 @@ impl<T: Reader> T : ReaderUtil {
190190

191191
fn read_whole_stream() -> ~[u8] {
192192
let mut buf: ~[u8] = ~[];
193-
while !self.eof() { vec::push_all(buf, self.read_bytes(2048u)); }
193+
while !self.eof() { buf.push_all(self.read_bytes(2048u)); }
194194
move buf
195195
}
196196

@@ -503,7 +503,7 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
503503

504504
let mut bytes: ~[u8] = ~[], i = size, n = n;
505505
while i > 0u {
506-
vec::push(bytes, (n & 255_u64) as u8);
506+
bytes.push((n & 255_u64) as u8);
507507
n >>= 8_u64;
508508
i -= 1u;
509509
}
@@ -535,7 +535,7 @@ fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
535535
let mut i = size;
536536
while i > 0u {
537537
let shift = ((i - 1u) * 8u) as u64;
538-
vec::push(bytes, (n >> shift) as u8);
538+
bytes.push((n >> shift) as u8);
539539
i -= 1u;
540540
}
541541
f(bytes)
@@ -737,7 +737,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str {
737737
let mut v = with_bytes_writer(f);
738738
739739
// Make sure the vector has a trailing null and is proper utf8.
740-
vec::push(v, 0);
740+
v.push(0);
741741
assert str::is_utf8(v);
742742
743743
unsafe { move ::cast::transmute(v) }

src/libcore/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ mod global_env {
219219
for vec::each(rustrt::rust_env_pairs()) |p| {
220220
let vs = str::splitn_char(*p, '=', 1u);
221221
assert vec::len(vs) == 2u;
222-
vec::push(pairs, (copy vs[0], copy vs[1]));
222+
pairs.push((copy vs[0], copy vs[1]));
223223
}
224224
move pairs
225225
}

0 commit comments

Comments
 (0)