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

+2-2
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

+4-5
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

+3-3
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

+5-5
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

+3-3
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

+2-2
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

+3-5
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

+1-1
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

+1-1
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

+1-2
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

src/librustc/middle/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,13 @@ pub fn specialize(cx: &MatchCheckCtxt,
642642
ty_to_str(cx.tcx, left_ty)));
643643
}
644644
}
645-
let args = vec::map(class_fields, |class_field| {
645+
let args = class_fields.iter().transform(|class_field| {
646646
match flds.iter().find_(|f|
647647
f.ident == class_field.ident) {
648648
Some(f) => f.pat,
649649
_ => wild()
650650
}
651-
});
651+
}).collect();
652652
Some(vec::append(args, vec::to_owned(r.tail())))
653653
}
654654
}

src/librustc/middle/const_eval.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use syntax::ast::*;
1919

2020
use std::float;
2121
use std::hashmap::{HashMap, HashSet};
22-
use std::vec;
2322

2423
//
2524
// This pass classifies expressions by their constant-ness.
@@ -70,8 +69,8 @@ pub fn join(a: constness, b: constness) -> constness {
7069
}
7170
}
7271

73-
pub fn join_all(cs: &[constness]) -> constness {
74-
cs.iter().fold(integral_const, |a, b| join(a, *b))
72+
pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
73+
cs.fold(integral_const, |a, b| join(a, b))
7574
}
7675

7776
pub fn classify(e: &expr,
@@ -104,7 +103,7 @@ pub fn classify(e: &expr,
104103

105104
ast::expr_tup(ref es) |
106105
ast::expr_vec(ref es, ast::m_imm) => {
107-
join_all(vec::map(*es, |e| classify(*e, tcx)))
106+
join_all(es.iter().transform(|e| classify(*e, tcx)))
108107
}
109108

110109
ast::expr_vstore(e, vstore) => {
@@ -118,7 +117,7 @@ pub fn classify(e: &expr,
118117
}
119118

120119
ast::expr_struct(_, ref fs, None) => {
121-
let cs = do vec::map((*fs)) |f| {
120+
let cs = do fs.iter().transform |f| {
122121
classify(f.node.expr, tcx)
123122
};
124123
join_all(cs)

src/librustc/middle/lint.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,10 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
740740
}
741741

742742
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
743-
let tys = vec::map(decl.inputs, |a| a.ty );
744-
let r = vec::append_one(tys, decl.output);
745-
for r.iter().advance |ty| {
746-
check_ty(cx, *ty);
743+
for decl.inputs.iter().advance |in| {
744+
check_ty(cx, in.ty);
747745
}
746+
check_ty(cx, decl.output)
748747
}
749748

750749
match it.node {

src/librustc/middle/trans/adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: int,
519519
C_struct(build_const_struct(ccx, nonnull, vals))
520520
} else {
521521
assert_eq!(vals.len(), 0);
522-
let vals = do nonnull.fields.mapi |i, &ty| {
522+
let vals = do nonnull.fields.iter().enumerate().transform |(i, &ty)| {
523523
let llty = type_of::sizing_type_of(ccx, ty);
524524
if i == ptrfield { C_null(llty) } else { C_undef(llty) }
525-
};
525+
}.collect::<~[ValueRef]>();
526526
C_struct(build_const_struct(ccx, nonnull, vals))
527527
}
528528
}

src/librustc/middle/trans/build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,12 @@ pub fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
615615
// we care about.
616616
if ixs.len() < 16 {
617617
let mut small_vec = [ C_i32(0), ..16 ];
618-
for ixs.iter().enumerate().advance |(i, &ix)| {
619-
small_vec[i] = C_i32(ix as i32)
618+
for small_vec.mut_iter().zip(ixs.iter()).advance |(small_vec_e, &ix)| {
619+
*small_vec_e = C_i32(ix as i32);
620620
}
621621
InBoundsGEP(cx, base, small_vec.slice(0, ixs.len()))
622622
} else {
623-
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
623+
let v = do ixs.iter().transform |i| { C_i32(*i as i32) }.collect::<~[ValueRef]>();
624624
count_insn(cx, "gepi");
625625
InBoundsGEP(cx, base, v)
626626
}

src/librustc/middle/trans/cabi.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use middle::trans::type_::Type;
1717

1818
use std::libc::c_uint;
1919
use std::option;
20-
use std::vec;
2120

2221
pub trait ABIInfo {
2322
fn compute_info(&self, atys: &[Type], rty: Type, ret_def: bool) -> FnType;
@@ -37,7 +36,7 @@ pub struct FnType {
3736

3837
impl FnType {
3938
pub fn decl_fn(&self, decl: &fn(fnty: Type) -> ValueRef) -> ValueRef {
40-
let atys = vec::map(self.arg_tys, |t| t.ty);
39+
let atys = self.arg_tys.iter().transform(|t| t.ty).collect::<~[Type]>();
4140
let rty = self.ret_ty.ty;
4241
let fnty = Type::func(atys, &rty);
4342
let llfn = decl(fnty);

src/librustc/middle/trans/common.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,9 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] {
980980

981981
match bcx.fcx.param_substs {
982982
Some(substs) => {
983-
do vec::map(params) |t| {
983+
do params.iter().transform |t| {
984984
ty::subst_tps(tcx, substs.tys, substs.self_ty, *t)
985-
}
985+
}.collect()
986986
}
987987
_ => params
988988
}
@@ -1006,9 +1006,11 @@ pub fn resolve_vtables_under_param_substs(tcx: ty::ctxt,
10061006
param_substs: Option<@param_substs>,
10071007
vts: typeck::vtable_res)
10081008
-> typeck::vtable_res {
1009-
@vec::map(*vts, |ds|
1010-
@vec::map(**ds, |d|
1011-
resolve_vtable_under_param_substs(tcx, param_substs, copy *d)))
1009+
@vts.iter().transform(|ds|
1010+
@ds.iter().transform(
1011+
|d| resolve_vtable_under_param_substs(tcx, param_substs, copy *d))
1012+
.collect::<~[typeck::vtable_origin]>())
1013+
.collect::<~[typeck::vtable_param_res]>()
10121014
}
10131015

10141016

@@ -1029,9 +1031,9 @@ pub fn resolve_vtable_under_param_substs(tcx: ty::ctxt,
10291031
typeck::vtable_static(trait_id, tys, sub) => {
10301032
let tys = match param_substs {
10311033
Some(substs) => {
1032-
do vec::map(tys) |t| {
1034+
do tys.iter().transform |t| {
10331035
ty::subst_tps(tcx, substs.tys, substs.self_ty, *t)
1034-
}
1036+
}.collect()
10351037
}
10361038
_ => tys
10371039
};

src/librustc/middle/trans/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
588588
}
589589
ast::expr_tup(ref args) => {
590590
let repr = adt::represent_type(bcx.ccx(), expr_ty(bcx, expr));
591-
return trans_adt(bcx, repr, 0, args.mapi(|i, arg| (i, *arg)),
592-
None, dest);
591+
let numbered_fields: ~[(uint, @ast::expr)] =
592+
args.iter().enumerate().transform(|(i, arg)| (i, *arg)).collect();
593+
return trans_adt(bcx, repr, 0, numbered_fields, None, dest);
593594
}
594595
ast::expr_lit(@codemap::spanned {node: ast::lit_str(s), _}) => {
595596
return tvec::trans_lit_str(bcx, expr, s, dest);

0 commit comments

Comments
 (0)