Skip to content

Commit f661a15

Browse files
committed
std: remove vec::each2 and vec::each2_mut in favour of iterators
1 parent 5e9f006 commit f661a15

File tree

10 files changed

+24
-97
lines changed

10 files changed

+24
-97
lines changed

src/librustc/middle/kind.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use middle::typeck;
1717
use util::ppaux::{Repr, ty_to_str};
1818
use util::ppaux::UserString;
1919

20+
use core::iterator::IteratorUtil;
2021
use core::vec;
2122
use syntax::ast::*;
2223
use syntax::attr::attrs_contains_name;
@@ -268,7 +269,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
268269
ts.repr(cx.tcx),
269270
type_param_defs.repr(cx.tcx));
270271
}
271-
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
272+
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
272273
check_bounds(cx, type_parameter_id, e.span, ty, type_param_def)
273274
}
274275
}
@@ -309,7 +310,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
309310
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
310311
let type_param_defs =
311312
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
312-
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
313+
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
313314
check_bounds(cx, aty.id, aty.span, ty, type_param_def)
314315
}
315316
}

src/librustc/middle/trans/inline.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use middle::trans::common::*;
1919
use middle::ty;
2020
use util::ppaux::ty_to_str;
2121

22+
use core::iterator::IteratorUtil;
2223
use core::vec;
2324
use syntax::ast;
2425
use syntax::ast_map::path_name;
@@ -75,7 +76,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
7576
ast::item_enum(_, _) => {
7677
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
7778
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
78-
for vec::each2(*vs_here, *vs_there) |here, there| {
79+
for vs_here.iter().zip(vs_there.iter()).advance |(here, there)| {
7980
if there.id == fn_id { my_id = here.id.node; }
8081
ccx.external.insert(there.id, Some(here.id.node));
8182
}

src/librustc/middle/trans/type_use.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use middle::trans::inline;
3333
use middle::ty;
3434
use middle::typeck;
3535

36+
use core::iterator::IteratorUtil;
3637
use core::option::{Some, None};
3738
use core::uint;
3839
use core::vec;
@@ -264,7 +265,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
264265
for opt_static_did.each |&did| {
265266
for cx.ccx.tcx.node_type_substs.find_copy(&callee_id).each |ts| {
266267
let type_uses = type_uses_for(cx.ccx, did, ts.len());
267-
for vec::each2(*type_uses, *ts) |uses, subst| {
268+
for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
268269
type_needs(cx, *uses, *subst)
269270
}
270271
}
@@ -302,7 +303,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
302303
for opt_ts.each |ts| {
303304
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get_copy(&e.id));
304305
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
305-
for vec::each2(*uses_for_ts, *ts) |uses, subst| {
306+
for uses_for_ts.iter().zip(ts.iter()).advance |(uses, subst)| {
306307
type_needs(cx, *uses, *subst)
307308
}
308309
}

src/librustc/middle/typeck/check/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use middle::typeck::check::{instantiate_path, lookup_def};
1818
use middle::typeck::check::{structure_of, valid_range_bounds};
1919
use middle::typeck::require_same_types;
2020

21+
use core::iterator::IteratorUtil;
2122
use core::hashmap::{HashMap, HashSet};
22-
use core::vec;
2323
use syntax::ast;
2424
use syntax::ast_util;
2525
use syntax::codemap::span;
@@ -232,7 +232,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
232232
233233
if !error_happened {
234234
for subpats.each |pats| {
235-
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
235+
for pats.iter().zip(arg_types.iter()).advance |(subpat, arg_ty)| {
236236
check_pat(pcx, *subpat, *arg_ty);
237237
}
238238
}

src/librustc/middle/typeck/check/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ use util::common::{block_query, indenter, loop_query};
110110
use util::ppaux::{bound_region_to_str};
111111
use util::ppaux;
112112

113+
114+
use core::iterator::IteratorUtil;
113115
use core::cast::transmute;
114116
use core::hashmap::HashMap;
115117
use core::result;
@@ -412,7 +414,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
412414
for opt_self_info.each |self_info| {
413415
fcx.write_ty(self_info.self_id, self_info.self_ty);
414416
}
415-
for vec::each2(decl.inputs, arg_tys) |input, arg| {
417+
for decl.inputs.iter().zip(arg_tys.iter()).advance |(input, arg)| {
416418
fcx.write_ty(input.id, *arg);
417419
}
418420

@@ -449,7 +451,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
449451
}
450452

451453
// Add formal parameters.
452-
for vec::each2(arg_tys, decl.inputs) |arg_ty, input| {
454+
for arg_tys.iter().zip(decl.inputs.iter()).advance |(arg_ty, input)| {
453455
// Create type variables for each argument.
454456
do pat_util::pat_bindings(tcx.def_map, input.pat)
455457
|_bm, pat_id, _sp, _path| {

src/librustc/middle/typeck/coherence.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ use syntax::visit::{Visitor, SimpleVisitor};
5454
use syntax::visit::{visit_mod};
5555
use util::ppaux::ty_to_str;
5656

57+
use core::iterator::IteratorUtil;
5758
use core::hashmap::{HashMap, HashSet};
5859
use core::old_iter;
5960
use core::result::Ok;
@@ -617,9 +618,9 @@ impl CoherenceChecker {
617618
// Check to ensure that each parameter binding respected its
618619
// kind bounds.
619620
for [ a, b ].each |result| {
620-
for vec::each2(result.type_variables,
621-
*result.type_param_defs)
622-
|ty_var, type_param_def|
621+
for result.type_variables.iter()
622+
.zip(result.type_param_defs.iter())
623+
.advance |(ty_var, type_param_def)|
623624
{
624625
if type_param_def.bounds.builtin_bounds.contains_elem(
625626
ty::BoundCopy)

src/libstd/vec.rs

-38
Original file line numberDiff line numberDiff line change
@@ -1666,44 +1666,6 @@ pub fn eachi_reverse<'r,T>(v: &'r [T],
16661666
return true;
16671667
}
16681668

1669-
/**
1670-
* Iterates over two vectors simultaneously
1671-
*
1672-
* # Failure
1673-
*
1674-
* Both vectors must have the same length
1675-
*/
1676-
#[inline]
1677-
pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
1678-
assert_eq!(v1.len(), v2.len());
1679-
for uint::range(0u, v1.len()) |i| {
1680-
if !f(&v1[i], &v2[i]) {
1681-
return false;
1682-
}
1683-
}
1684-
return true;
1685-
}
1686-
1687-
/**
1688-
*
1689-
* Iterates over two vector with mutable.
1690-
*
1691-
* # Failure
1692-
*
1693-
* Both vectors must have the same length
1694-
*/
1695-
#[inline]
1696-
pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T],
1697-
f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
1698-
assert_eq!(v1.len(), v2.len());
1699-
for uint::range(0u, v1.len()) |i| {
1700-
if !f(&mut v1[i], &mut v2[i]) {
1701-
return false;
1702-
}
1703-
}
1704-
return true;
1705-
}
1706-
17071669
/**
17081670
* Iterate over all permutations of vector `v`.
17091671
*

src/libsyntax/ext/deriving/generic.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ use opt_vec;
174174

175175
use core::uint;
176176
use core::vec;
177+
use core::iterator::IteratorUtil;
177178

178179
pub use self::ty::*;
179180
mod ty;
@@ -616,7 +617,7 @@ impl<'self> MethodDef<'self> {
616617
// make a series of nested matches, to destructure the
617618
// structs. This is actually right-to-left, but it shoudn't
618619
// matter.
619-
for vec::each2(self_args, patterns) |&arg_expr, &pat| {
620+
for self_args.iter().zip(patterns.iter()).advance |(&arg_expr, &pat)| {
620621
body = cx.expr_match(span, arg_expr,
621622
~[ cx.arm(span, ~[pat], body) ])
622623
}
@@ -951,7 +952,7 @@ fn create_struct_pattern(cx: @ExtCtxt,
951952
// must be nonempty to reach here
952953
let pattern = if struct_type == Record {
953954
let field_pats = do vec::build |push| {
954-
for vec::each2(subpats, ident_expr) |&pat, &(id, _)| {
955+
for subpats.iter().zip(ident_expr.iter()).advance |(&pat, &(id, _))| {
955956
// id is guaranteed to be Some
956957
push(ast::field_pat { ident: id.get(), pat: pat })
957958
}

src/test/bench/shootout-fannkuch-redux.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::iterator::*;
12
use std::from_str::FromStr;
23
use std::i32::range;
34
use std::os;
@@ -29,9 +30,8 @@ fn fannkuch_redux(n: i32) -> i32 {
2930
r -= 1;
3031
}
3132

32-
// XXX: Need each2_mut.
33-
for vec::eachi_mut(perm) |i, perm_i| {
34-
*perm_i = perm1.unsafe_get(i);
33+
for perm.mut_iter().zip(perm1.iter()).advance |(perm_i, perm1_i)| {
34+
*perm_i = *perm1_i;
3535
}
3636

3737
let mut flips_count: i32 = 0;

src/test/run-pass/vec-each2_mut.rs

-42
This file was deleted.

0 commit comments

Comments
 (0)