Skip to content

Commit c0a20d2

Browse files
committed
Remove vec::{map, mapi, zip_map} and the methods, except for .map, since this
is very common, and the replacement (.iter().transform().collect()) is very ugly.
1 parent a396e1e commit c0a20d2

Some content is hidden

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

47 files changed

+184
-310
lines changed

src/compiletest/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
345345
fatal(~"process did not return an error status");
346346
}
347347

348-
let prefixes = vec::map(expected_errors, |ee| {
348+
let prefixes = expected_errors.iter().transform(|ee| {
349349
fmt!("%s:%u:", testfile.to_str(), ee.line)
350-
});
350+
}).collect::<~[~str]>();
351351

352352
// Scan and extract our error/warning messages,
353353
// which look like:

src/libextra/fileinput.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ total line count).
100100
use std::io::ReaderUtil;
101101
use std::io;
102102
use std::os;
103-
use std::vec;
104103

105104
/**
106105
A summary of the internal state of a `FileInput` object. `line_num`
@@ -353,13 +352,13 @@ a literal `-`.
353352
*/
354353
// XXX: stupid, unclear name
355354
pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
356-
vec::map(vec, |&str : & ~str| {
357-
if stdin_hyphen && str == ~"-" {
355+
vec.iter().transform(|str| {
356+
if stdin_hyphen && "-" == *str {
358357
None
359358
} else {
360-
Some(Path(str))
359+
Some(Path(*str))
361360
}
362-
})
361+
}).collect()
363362
}
364363

365364
/**

src/libextra/getopts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ pub mod groups {
592592
*/
593593
pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
594594

595-
let desc_sep = ~"\n" + " ".repeat(24);
595+
let desc_sep = "\n" + " ".repeat(24);
596596

597-
let rows = vec::map(opts, |optref| {
597+
let mut rows = opts.iter().transform(|optref| {
598598
let OptGroup{short_name: short_name,
599599
long_name: long_name,
600600
hint: hint,
@@ -669,7 +669,7 @@ pub mod groups {
669669

670670
return str::to_owned(brief) +
671671
"\n\nOptions:\n" +
672-
rows.connect("\n") +
672+
rows.collect::<~[~str]>().connect("\n") +
673673
"\n\n";
674674
}
675675
} // end groups module

src/libextra/num/bigint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ impl Mul<BigUint, BigUint> for BigUint {
283283
if n == 1 { return copy *a; }
284284

285285
let mut carry = 0;
286-
let prod = do vec::map(a.data) |ai| {
286+
let prod = do a.data.iter().transform |ai| {
287287
let (hi, lo) = BigDigit::from_uint(
288288
(*ai as uint) * (n as uint) + (carry as uint)
289289
);
290290
carry = hi;
291291
lo
292-
};
292+
}.collect::<~[BigDigit]>();
293293
if carry == 0 { return BigUint::new(prod) };
294294
return BigUint::new(prod + [carry]);
295295
}
@@ -618,13 +618,13 @@ impl BigUint {
618618
if n_bits == 0 || self.is_zero() { return copy *self; }
619619

620620
let mut carry = 0;
621-
let shifted = do vec::map(self.data) |elem| {
621+
let shifted = do self.data.iter().transform |elem| {
622622
let (hi, lo) = BigDigit::from_uint(
623623
(*elem as uint) << n_bits | (carry as uint)
624624
);
625625
carry = hi;
626626
lo
627-
};
627+
}.collect::<~[BigDigit]>();
628628
if carry == 0 { return BigUint::new(shifted); }
629629
return BigUint::new(shifted + [carry]);
630630
}
@@ -1172,7 +1172,7 @@ mod biguint_tests {
11721172
11731173
#[test]
11741174
fn test_cmp() {
1175-
let data = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]
1175+
let data: ~[BigUint] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]
11761176
.map(|v| BigUint::from_slice(*v));
11771177
for data.iter().enumerate().advance |(i, ni)| {
11781178
for data.slice(i, data.len()).iter().enumerate().advance |(j0, nj)| {

src/libextra/par.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn map<A:Copy + Send,B:Copy + Send>(
9292
vec::concat(map_slices(xs, || {
9393
let f = fn_factory();
9494
let result: ~fn(uint, &[A]) -> ~[B] =
95-
|_, slice| vec::map(slice, |x| f(x));
95+
|_, slice| slice.iter().transform(|x| f(x)).collect();
9696
result
9797
}))
9898
}
@@ -104,9 +104,9 @@ pub fn mapi<A:Copy + Send,B:Copy + Send>(
104104
let slices = map_slices(xs, || {
105105
let f = fn_factory();
106106
let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| {
107-
vec::mapi(slice, |i, x| {
107+
slice.iter().enumerate().transform(|(i, x)| {
108108
f(i + base, x)
109-
})
109+
}).collect()
110110
};
111111
result
112112
});

src/libextra/semver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ impl ToStr for Version {
7878
let s = if self.pre.is_empty() {
7979
s
8080
} else {
81-
s + "-" + self.pre.map(|i| i.to_str()).connect(".")
81+
fmt!("%s-%s", s, self.pre.map(|i| i.to_str()).connect("."))
8282
};
8383
if self.build.is_empty() {
8484
s
8585
} else {
86-
s + "+" + self.build.map(|i| i.to_str()).connect(".")
86+
fmt!("%s+%s", s, self.build.map(|i| i.to_str()).connect("."))
8787
}
8888
}
8989
}

src/librustc/back/rpath.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
5252
}
5353

5454
pub fn rpaths_to_flags(rpaths: &[Path]) -> ~[~str] {
55-
vec::map(rpaths, |rpath| fmt!("-Wl,-rpath,%s",rpath.to_str()))
55+
rpaths.iter().transform(|rpath| fmt!("-Wl,-rpath,%s",rpath.to_str())).collect()
5656
}
5757

5858
fn get_rpaths(os: session::os,
@@ -103,9 +103,7 @@ fn get_rpaths(os: session::os,
103103
fn get_rpaths_relative_to_output(os: session::os,
104104
output: &Path,
105105
libs: &[Path]) -> ~[Path] {
106-
vec::map(libs, |a| {
107-
get_rpath_relative_to_output(os, output, a)
108-
})
106+
libs.iter().transform(|a| get_rpath_relative_to_output(os, output, a)).collect()
109107
}
110108

111109
pub fn get_rpath_relative_to_output(os: session::os,
@@ -163,7 +161,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
163161
}
164162

165163
fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
166-
vec::map(libs, |a| get_absolute_rpath(a) )
164+
libs.iter().transform(|a| get_absolute_rpath(a)).collect()
167165
}
168166

169167
pub fn get_absolute_rpath(lib: &Path) -> Path {

src/librustc/front/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn fold_foreign_mod(
9090
ast::foreign_mod {
9191
sort: nm.sort,
9292
abis: nm.abis,
93-
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
93+
view_items: filtered_view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
9494
items: filtered_items
9595
}
9696
}

src/librustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn fold_mod(cx: @mut TestCtxt,
117117

118118
let mod_nomain = ast::_mod {
119119
view_items: /*bad*/copy m.view_items,
120-
items: vec::map(m.items, |i| nomain(cx, *i)),
120+
items: m.items.iter().transform(|i| nomain(cx, *i)).collect(),
121121
};
122122

123123
fold::noop_fold_mod(&mod_nomain, fld)

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,7 @@ fn encode_crate_deps(ecx: &EncodeContext,
14411441
expected_cnum += 1;
14421442
}
14431443

1444-
// mut -> immutable hack for vec::map
1445-
deps.slice(0, deps.len()).to_owned()
1444+
deps
14461445
}
14471446

14481447
// We're just going to write a list of crate 'name-hash-version's, with

0 commit comments

Comments
 (0)