Skip to content

Commit 513d229

Browse files
committed
std: remove foldr and alli methods in vec
1 parent ed299af commit 513d229

File tree

14 files changed

+26
-37
lines changed

14 files changed

+26
-37
lines changed

doc/tutorial-tasks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ a single large vector of floats. Each task needs the full vector to perform its
351351
# use std::vec;
352352
# use std::uint;
353353
# use std::rand;
354+
# use std::iterator::IteratorUtil;
354355
use extra::arc::ARC;
355356
356357
fn pnorm(nums: &~[float], p: uint) -> float {

src/librustc/middle/check_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use middle::typeck::method_map;
1919
use middle::moves;
2020
use util::ppaux::ty_to_str;
2121

22+
use core::iterator::IteratorUtil;
2223
use core::uint;
2324
use core::vec;
2425
use extra::sort;
@@ -242,7 +243,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
242243
not_useful
243244
}
244245
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
245-
let max_len = do m.foldr(0) |r, max_len| {
246+
let max_len = do m.rev_iter().fold(0) |max_len, r| {
246247
match r[0].node {
247248
pat_vec(ref before, _, ref after) => {
248249
uint::max(before.len() + after.len(), max_len)

src/librustc/middle/liveness.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ use middle::ty;
110110
use middle::typeck;
111111
use middle::moves;
112112

113+
use core::iterator::IteratorUtil;
113114
use core::cast::transmute;
114115
use core::hashmap::HashMap;
115116
use core::io;
@@ -923,7 +924,7 @@ impl Liveness {
923924
pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode)
924925
-> LiveNode {
925926
let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
926-
do blk.node.stmts.foldr(succ) |stmt, succ| {
927+
do blk.node.stmts.rev_iter().fold(succ) |succ, stmt| {
927928
self.propagate_through_stmt(*stmt, succ)
928929
}
929930
}
@@ -977,7 +978,7 @@ impl Liveness {
977978

978979
pub fn propagate_through_exprs(&self, exprs: &[@expr], succ: LiveNode)
979980
-> LiveNode {
980-
do exprs.foldr(succ) |expr, succ| {
981+
do exprs.rev_iter().fold(succ) |succ, expr| {
981982
self.propagate_through_expr(*expr, succ)
982983
}
983984
}
@@ -1021,7 +1022,7 @@ impl Liveness {
10211022
// the construction of a closure itself is not important,
10221023
// but we have to consider the closed over variables.
10231024
let caps = self.ir.captures(expr);
1024-
do caps.foldr(succ) |cap, succ| {
1025+
do caps.rev_iter().fold(succ) |succ, cap| {
10251026
self.init_from_succ(cap.ln, succ);
10261027
let var = self.variable(cap.var_nid, expr.span);
10271028
self.acc(cap.ln, var, ACC_READ | ACC_USE);
@@ -1159,7 +1160,7 @@ impl Liveness {
11591160

11601161
expr_struct(_, ref fields, with_expr) => {
11611162
let succ = self.propagate_through_opt_expr(with_expr, succ);
1162-
do (*fields).foldr(succ) |field, succ| {
1163+
do fields.rev_iter().fold(succ) |succ, field| {
11631164
self.propagate_through_expr(field.node.expr, succ)
11641165
}
11651166
}
@@ -1215,10 +1216,10 @@ impl Liveness {
12151216
}
12161217

12171218
expr_inline_asm(ref ia) =>{
1218-
let succ = do ia.inputs.foldr(succ) |&(_, expr), succ| {
1219+
let succ = do ia.inputs.rev_iter().fold(succ) |succ, &(_, expr)| {
12191220
self.propagate_through_expr(expr, succ)
12201221
};
1221-
do ia.outputs.foldr(succ) |&(_, expr), succ| {
1222+
do ia.outputs.rev_iter().fold(succ) |succ, &(_, expr)| {
12221223
self.propagate_through_expr(expr, succ)
12231224
}
12241225
}

src/librustc/middle/trans/adt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* taken to it, implementing them for Rust seems difficult.
4545
*/
4646

47+
use core::iterator::IteratorUtil;
4748
use core::container::Map;
4849
use core::libc::c_ulonglong;
4950
use core::option::{Option, Some, None};
@@ -176,7 +177,7 @@ fn represent_type_uncached(cx: @CrateContext, t: ty::t) -> Repr {
176177
// Since there's at least one
177178
// non-empty body, explicit discriminants should have
178179
// been rejected by a checker before this point.
179-
if !cases.alli(|i,c| c.discr == (i as int)) {
180+
if !cases.iter().enumerate().all(|(i,c)| c.discr == (i as int)) {
180181
cx.sess.bug(fmt!("non-C-like enum %s with specified \
181182
discriminants",
182183
ty::item_path_str(cx.tcx, def_id)))

src/librustc/middle/trans/cabi_arm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::trans::common::{T_array, T_ptr, T_void};
2020
use core::iterator::IteratorUtil;
2121
use core::option::{Option, None, Some};
2222
use core::uint;
23-
use core::vec;
2423

2524
fn align_up_to(off: uint, a: uint) -> uint {
2625
return (off + a - 1u) / a * a;

src/libstd/vec.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,11 +1821,9 @@ pub trait ImmutableVector<'self, T> {
18211821
fn last_opt(&self) -> Option<&'self T>;
18221822
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
18231823
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
1824-
fn foldr<'a, U>(&'a self, z: U, p: &fn(t: &'a T, u: U) -> U) -> U;
18251824
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
18261825
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
18271826
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U];
1828-
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
18291827
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
18301828
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
18311829
unsafe fn unsafe_ref(&self, index: uint) -> *T;
@@ -1913,12 +1911,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
19131911
rposition(*self, f)
19141912
}
19151913

1916-
/// Reduce a vector from right to left
1917-
#[inline]
1918-
fn foldr<'a, U>(&'a self, z: U, p: &fn(t: &'a T, u: U) -> U) -> U {
1919-
self.rev_iter().fold(z, |u, t| p(t, u))
1920-
}
1921-
19221914
/// Apply a function to each element of a vector and return the results
19231915
#[inline]
19241916
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
@@ -1942,14 +1934,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
19421934
r
19431935
}
19441936

1945-
/**
1946-
* Returns true if the function returns true for all elements.
1947-
*
1948-
* If the vector is empty, true is returned.
1949-
*/
1950-
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
1951-
self.iter().enumerate().all(|(i, t)| f(i,t))
1952-
}
19531937
/**
19541938
* Apply a function to each element of a vector and return a concatenation
19551939
* of each result vector

src/libsyntax/ast_util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use opt_vec;
2020
use parse::token;
2121
use visit;
2222

23+
use core::iterator::IteratorUtil;
2324
use core::hashmap::HashMap;
2425
use core::int;
2526
use core::option;
@@ -833,7 +834,7 @@ mod test {
833834
// returning the resulting index
834835
fn unfold_test_sc(tscs : ~[TestSC], tail: SyntaxContext, table : &mut SCTable)
835836
-> SyntaxContext {
836-
tscs.foldr(tail, |tsc : &TestSC,tail : SyntaxContext|
837+
tscs.rev_iter().fold(tail, |tail : SyntaxContext, tsc : &TestSC|
837838
{match *tsc {
838839
M(mrk) => new_mark_internal(mrk,tail,table),
839840
R(ident,name) => new_rename_internal(ident,name,tail,table)}})
@@ -874,7 +875,7 @@ mod test {
874875
// extend a syntax context with a sequence of marks given
875876
// in a vector. v[0] will be the outermost mark.
876877
fn unfold_marks(mrks:~[Mrk],tail:SyntaxContext,table: &mut SCTable) -> SyntaxContext {
877-
mrks.foldr(tail, |mrk:&Mrk,tail:SyntaxContext|
878+
mrks.rev_iter().fold(tail, |tail:SyntaxContext, mrk:&Mrk|
878879
{new_mark_internal(*mrk,tail,table)})
879880
}
880881

src/libsyntax/ext/deriving/generic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,11 @@ pub fn cs_fold(use_foldl: bool,
10251025
match *substructure.fields {
10261026
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
10271027
if use_foldl {
1028-
do all_fields.foldl(base) |&old, &(_, self_f, other_fs)| {
1028+
do all_fields.iter().fold(base) |old, &(_, self_f, other_fs)| {
10291029
f(cx, span, old, self_f, other_fs)
10301030
}
10311031
} else {
1032-
do all_fields.foldr(base) |&(_, self_f, other_fs), old| {
1032+
do all_fields.rev_iter().fold(base) |old, &(_, self_f, other_fs)| {
10331033
f(cx, span, old, self_f, other_fs)
10341034
}
10351035
}
@@ -1094,11 +1094,11 @@ pub fn cs_same_method_fold(use_foldl: bool,
10941094
cs_same_method(
10951095
|cx, span, vals| {
10961096
if use_foldl {
1097-
do vals.foldl(base) |&old, &new| {
1097+
do vals.iter().fold(base) |old, &new| {
10981098
f(cx, span, old, new)
10991099
}
11001100
} else {
1101-
do vals.foldr(base) |&new, old| {
1101+
do vals.rev_iter().fold(base) |old, &new| {
11021102
f(cx, span, old, new)
11031103
}
11041104
}

src/libsyntax/ext/deriving/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ library.
1919
*/
2020

2121
use core::prelude::*;
22+
use core::iterator::IteratorUtil;
2223

2324
use ast::{enum_def, ident, item, Generics, meta_item, struct_def};
2425
use ext::base::ExtCtxt;
@@ -74,7 +75,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt,
7475
in_items
7576
}
7677
meta_list(_, ref titems) => {
77-
do titems.foldr(in_items) |&titem, in_items| {
78+
do titems.rev_iter().fold(in_items) |in_items, &titem| {
7879
match titem.node {
7980
meta_name_value(tname, _) |
8081
meta_list(tname, _) |

src/test/bench/graph500-bfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn validate(edges: ~[(node_id, node_id)],
363363
364364
info!(~"Verifying tree edges...");
365365
366-
let status = do tree.alli() |k, parent| {
366+
let status = do tree.iter().enumerate().all |(k, parent)| {
367367
if *parent != root && *parent != -1i64 {
368368
level[*parent] == level[k] - 1
369369
}

src/test/compile-fail/issue-3044.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
let needlesArr: ~[char] = ~['a', 'f'];
1515
do needlesArr.iter().fold() |x, y| {
1616
}
17-
//~^ ERROR 1 parameter were supplied (including the closure passed by the `do` keyword)
17+
//~^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword)
1818
//
1919
// the first error is, um, non-ideal.
2020
}

src/test/run-pass/block-arg-can-be-followed-by-binop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::vec;
11+
use std::iterator::IteratorUtil;
1212

1313
pub fn main() {
1414
let v = ~[-1f, 0f, 1f, 2f, 3f];

src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::vec;
11+
use std::iterator::IteratorUtil;
1212

1313
pub fn main() {
1414
fn f(i: &fn() -> uint) -> uint { i() }

src/test/run-pass/block-arg-can-be-followed-by-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::vec;
11+
use std::iterator::IteratorUtil;
1212

1313
pub fn main() {
1414
fn f(i: uint) -> uint { i }

0 commit comments

Comments
 (0)