Skip to content

Commit 7ffa67c

Browse files
committed
front -- collapse iterator actions that require access to the same &mut state
1 parent ec6d122 commit 7ffa67c

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/librustc/front/config.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::ViewItem)
5858
}
5959

6060
fn fold_mod(cx: &mut Context, m: &ast::Mod) -> ast::Mod {
61-
let filtered_items = m.items.iter()
61+
let filtered_items: ~[&@ast::Item] = m.items.iter()
6262
.filter(|&a| item_in_cfg(cx, *a))
63+
.collect();
64+
let flattened_items = filtered_items.move_iter()
6365
.flat_map(|&x| cx.fold_item(x).move_iter())
6466
.collect();
6567
let filtered_view_items = m.view_items.iter().filter_map(|a| {
6668
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
6769
}).collect();
6870
ast::Mod {
6971
view_items: filtered_view_items,
70-
items: filtered_items
72+
items: flattened_items
7173
}
7274
}
7375

@@ -113,23 +115,26 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
113115
ast::ItemStruct(fold_struct(cx, def), generics.clone())
114116
}
115117
ast::ItemEnum(ref def, ref generics) => {
116-
let mut variants = def.variants.iter().map(|c| c.clone()).filter(|m| {
117-
(cx.in_cfg)(m.node.attrs)
118-
}).map(|v| {
119-
match v.node.kind {
120-
ast::TupleVariantKind(..) => v,
121-
ast::StructVariantKind(def) => {
122-
let def = fold_struct(cx, def);
123-
@codemap::Spanned {
124-
node: ast::Variant_ {
125-
kind: ast::StructVariantKind(def),
126-
..v.node.clone()
127-
},
128-
..*v
129-
}
118+
let mut variants = def.variants.iter().map(|c| c.clone()).
119+
filter_map(|v| {
120+
if !(cx.in_cfg)(v.node.attrs) {
121+
None
122+
} else {
123+
Some(match v.node.kind {
124+
ast::TupleVariantKind(..) => v,
125+
ast::StructVariantKind(def) => {
126+
let def = fold_struct(cx, def);
127+
@codemap::Spanned {
128+
node: ast::Variant_ {
129+
kind: ast::StructVariantKind(def),
130+
..v.node.clone()
131+
},
132+
..*v
133+
}
134+
}
135+
})
130136
}
131-
}
132-
});
137+
});
133138
ast::ItemEnum(ast::EnumDef {
134139
variants: variants.collect(),
135140
}, generics.clone())
@@ -165,10 +170,11 @@ fn retain_stmt(cx: &Context, stmt: @ast::Stmt) -> bool {
165170
}
166171

167172
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
168-
let resulting_stmts = b.stmts.iter()
169-
.filter(|&a| retain_stmt(cx, *a))
170-
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
171-
.collect();
173+
let resulting_stmts: ~[&@ast::Stmt] =
174+
b.stmts.iter().filter(|&a| retain_stmt(cx, *a)).collect();
175+
let resulting_stmts = resulting_stmts.move_iter()
176+
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())
177+
.collect();
172178
let filtered_view_items = b.view_items.iter().filter_map(|a| {
173179
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
174180
}).collect();

0 commit comments

Comments
 (0)