Skip to content

Commit

Permalink
Remove vec::{filter, filtered, filter_map, filter_mapped}, replaced b…
Browse files Browse the repository at this point in the history
…y iterators.
  • Loading branch information
huonw committed Jul 3, 2013
1 parent eee6775 commit de0d696
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 418 deletions.
8 changes: 4 additions & 4 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub fn filter_tests(
} else { return option::None; }
}
vec::filter_map(filtered, |x| filter_fn(x, filter_str))
filtered.consume_iter().filter_map(|x| filter_fn(x, filter_str)).collect()
};
// Maybe pull out the ignored test and unignore them
Expand All @@ -541,7 +541,7 @@ pub fn filter_tests(
None
}
};
vec::filter_map(filtered, |x| filter(x))
filtered.consume_iter().filter_map(|x| filter(x)).collect()
};
// Sort the tests alphabetically
Expand Down Expand Up @@ -720,9 +720,9 @@ impl BenchHarness {
// Eliminate outliers
let med = samples.median();
let mad = samples.median_abs_dev();
let samples = do vec::filter(samples) |f| {
let samples = do samples.consume_iter().filter |f| {
num::abs(*f - med) <= 3.0 * mad
};
}.collect::<~[f64]>();
debug!("%u samples, median %f, MAD=%f, %u survived filter",
n_samples, med as float, mad as float,
Expand Down
54 changes: 26 additions & 28 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


use std::option;
use std::vec;
use syntax::{ast, fold, attr};

type in_cfg_pred = @fn(attrs: ~[ast::attribute]) -> bool;
Expand Down Expand Up @@ -61,13 +60,15 @@ fn filter_view_item(cx: @Context, view_item: @ast::view_item
}

fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
let filtered_items =
m.items.filter_mapped(|a| filter_item(cx, *a));
let filtered_view_items =
m.view_items.filter_mapped(|a| filter_view_item(cx, *a));
let filtered_items = do m.items.iter().filter_map |a| {
filter_item(cx, *a).chain(|x| fld.fold_item(x))
}.collect();
let filtered_view_items = do m.view_items.iter().filter_map |a| {
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
}.collect();
ast::_mod {
view_items: filtered_view_items.map(|x| fld.fold_view_item(*x)),
items: vec::filter_map(filtered_items, |x| fld.fold_item(x))
view_items: filtered_view_items,
items: filtered_items
}
}

Expand All @@ -83,14 +84,14 @@ fn fold_foreign_mod(
nm: &ast::foreign_mod,
fld: @fold::ast_fold
) -> ast::foreign_mod {
let filtered_items =
nm.items.filter_mapped(|a| filter_foreign_item(cx, *a));
let filtered_view_items =
nm.view_items.filter_mapped(|a| filter_view_item(cx, *a));
let filtered_items = nm.items.iter().filter_map(|a| filter_foreign_item(cx, *a)).collect();
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
}.collect();
ast::foreign_mod {
sort: nm.sort,
abis: nm.abis,
view_items: filtered_view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
view_items: filtered_view_items,
items: filtered_items
}
}
Expand All @@ -99,11 +100,13 @@ fn fold_item_underscore(cx: @Context, item: &ast::item_,
fld: @fold::ast_fold) -> ast::item_ {
let item = match *item {
ast::item_impl(ref a, b, c, ref methods) => {
let methods = methods.filtered(|m| method_in_cfg(cx, *m) );
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
.transform(|x| *x).collect();
ast::item_impl(/*bad*/ copy *a, b, c, methods)
}
ast::item_trait(ref a, ref b, ref methods) => {
let methods = methods.filtered(|m| trait_method_in_cfg(cx, m) );
let methods = methods.iter().filter(|m| trait_method_in_cfg(cx, *m) )
.transform(|x| /* bad */copy *x).collect();
ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods)
}
ref item => /*bad*/ copy *item
Expand Down Expand Up @@ -134,19 +137,12 @@ fn fold_block(
b: &ast::blk_,
fld: @fold::ast_fold
) -> ast::blk_ {
let filtered_stmts =
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
let filtered_view_items =
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
let filtered_view_items =
filtered_view_items.map(|x| fld.fold_view_item(*x));
let mut resulting_stmts = ~[];
for filtered_stmts.iter().advance |stmt| {
match fld.fold_stmt(*stmt) {
None => {}
Some(stmt) => resulting_stmts.push(stmt),
}
}
let resulting_stmts = do b.stmts.iter().filter_map |a| {
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
}.collect();
let filtered_view_items = do b.view_items.iter().filter_map |a| {
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
}.collect();
ast::blk_ {
view_items: filtered_view_items,
stmts: resulting_stmts,
Expand Down Expand Up @@ -193,7 +189,9 @@ pub fn metas_in_cfg(cfg: &[@ast::meta_item],
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
// so we can match against them. This is the list of configurations for
// which the item is valid
let cfg_metas = vec::filter_map(cfg_metas, |i| attr::get_meta_item_list(i));
let cfg_metas = cfg_metas.consume_iter()
.filter_map(|i| attr::get_meta_item_list(i))
.collect::<~[~[@ast::meta_item]]>();

if cfg_metas.iter().all(|c| c.is_empty()) { return true; }

Expand Down
16 changes: 9 additions & 7 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ fn fold_mod(cx: @mut TestCtxt,

fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item {
if !*cx.sess.building_library {
@ast::item{attrs: item.attrs.filtered(|attr| {
"main" != attr::get_attr_name(attr)
}),.. copy *item}
@ast::item{
attrs: do item.attrs.iter().filter_map |attr| {
if "main" != attr::get_attr_name(attr) {Some(*attr)} else {None}
}.collect(),
.. copy *item}
} else { item }
}

Expand Down Expand Up @@ -229,10 +231,10 @@ fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool {
let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore");
let ignoreitems = attr::attr_metas(ignoreattrs);
return if !ignoreitems.is_empty() {
let cfg_metas =
vec::concat(
vec::filter_map(ignoreitems,
|i| attr::get_meta_item_list(i)));
let cfg_metas = ignoreitems.consume_iter()
.filter_map(|i| attr::get_meta_item_list(i))
.collect::<~[~[@ast::meta_item]]>()
.concat_vec();
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
} else {
false
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,16 @@ fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) {
// inlined items.
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ {
let stmts_sans_items = do blk.stmts.filtered |stmt| {
let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| {
match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
span: _}, _) => true,
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_),
span: _}, _) => false,
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_), span: _}, _)
=> Some(*stmt),
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_), span: _}, _)
=> None,
ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
}
};
}.collect();
let blk_sans_items = ast::blk_ {
view_items: ~[], // I don't know if we need the view_items here,
// but it doesn't break tests!
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, (s, v): ((), visit::vt<()>)) {
}
_ => { /* We assume only enum types can be uninhabited */ }
}
let arms = vec::concat(arms.filter_mapped(unguarded_pat));
let arms = arms.iter().filter_map(unguarded_pat).collect::<~[~[@pat]]>().concat_vec();
if arms.is_empty() {
cx.tcx.sess.span_err(ex.span, "non-exhaustive patterns");
} else {
Expand Down Expand Up @@ -265,7 +265,7 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
}
Some(ref ctor) => {
match is_useful(cx,
&m.filter_mapped(|r| default(cx, *r)),
&m.iter().filter_map(|r| default(cx, *r)).collect::<matrix>(),
v.tail()) {
useful_ => useful(left_ty, /*bad*/copy *ctor),
ref u => (/*bad*/copy *u)
Expand All @@ -287,7 +287,7 @@ pub fn is_useful_specialized(cx: &MatchCheckCtxt,
arity: uint,
lty: ty::t)
-> useful {
let ms = m.filter_mapped(|r| specialize(cx, *r, &ctor, arity, lty));
let ms = m.iter().filter_map(|r| specialize(cx, *r, &ctor, arity, lty)).collect::<matrix>();
let could_be_useful = is_useful(
cx, &ms, specialize(cx, v, &ctor, arity, lty).get());
match could_be_useful {
Expand Down Expand Up @@ -397,14 +397,14 @@ pub fn missing_ctor(cx: &MatchCheckCtxt,
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {

// Find the lengths and slices of all vector patterns.
let vec_pat_lens = do m.filter_mapped |r| {
let vec_pat_lens = do m.iter().filter_map |r| {
match r[0].node {
pat_vec(ref before, ref slice, ref after) => {
Some((before.len() + after.len(), slice.is_some()))
}
_ => None
}
};
}.collect::<~[(uint, bool)]>();

// Sort them by length such that for patterns of the same length,
// those with a destructured slice come first.
Expand Down
11 changes: 7 additions & 4 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use util::ppaux;
use middle::trans::type_::Type;

use std::str;
use std::vec;
use syntax::ast;
use syntax::ast::ident;
use syntax::ast_map::path_mod;
Expand Down Expand Up @@ -190,9 +189,13 @@ pub fn trans_log(log_ex: &ast::expr,

let (modpath, modname) = {
let path = &mut bcx.fcx.path;
let modpath = vec::append(
~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))],
path.filtered(|e| match *e { path_mod(_) => true, _ => false }));
let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
for path.iter().advance |e| {
match *e {
path_mod(_) => { modpath.push(*e) }
_ => {}
}
}
let modname = path_str(ccx.sess, modpath);
(modpath, modname)
};
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/attr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn parse_crate(attrs: ~[ast::attribute]) -> CrateAttrs {
}

pub fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> {
let doc_strs = do doc_metas(attrs).filter_mapped |meta| {
attr::get_meta_item_value_str(*meta).map(|s| s.to_owned())
};
let doc_strs = do doc_metas(attrs).consume_iter().filter_map |meta| {
attr::get_meta_item_value_str(meta).map(|s| s.to_owned())
}.collect::<~[~str]>();
if doc_strs.is_empty() {
None
} else {
Expand Down
Loading

0 comments on commit de0d696

Please sign in to comment.