Skip to content

Commit a69eb95

Browse files
AatchJames Miller
authored andcommitted
Stop allocating view_items with @
1 parent 63f7857 commit a69eb95

File tree

11 files changed

+52
-55
lines changed

11 files changed

+52
-55
lines changed

src/librustc/front/config.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::option;
1313
use syntax::{ast, fold, attr};
1414

15-
type in_cfg_pred = @fn(attrs: ~[ast::attribute]) -> bool;
15+
type in_cfg_pred = @fn(attrs: &[ast::attribute]) -> bool;
1616

1717
struct Context {
1818
in_cfg: in_cfg_pred
@@ -50,8 +50,7 @@ fn filter_item(cx: @Context, item: @ast::item) ->
5050
if item_in_cfg(cx, item) { option::Some(item) } else { option::None }
5151
}
5252

53-
fn filter_view_item(cx: @Context, view_item: @ast::view_item
54-
)-> Option<@ast::view_item> {
53+
fn filter_view_item<'r>(cx: @Context, view_item: &'r ast::view_item)-> Option<&'r ast::view_item> {
5554
if view_item_in_cfg(cx, view_item) {
5655
option::Some(view_item)
5756
} else {
@@ -64,7 +63,7 @@ fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
6463
filter_item(cx, *a).chain(|x| fld.fold_item(x))
6564
}.collect();
6665
let filtered_view_items = do m.view_items.iter().filter_map |a| {
67-
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
66+
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
6867
}.collect();
6968
ast::_mod {
7069
view_items: filtered_view_items,
@@ -86,7 +85,7 @@ fn fold_foreign_mod(
8685
) -> ast::foreign_mod {
8786
let filtered_items = nm.items.iter().filter_map(|a| filter_foreign_item(cx, *a)).collect();
8887
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
89-
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
88+
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
9089
}.collect();
9190
ast::foreign_mod {
9291
sort: nm.sort,
@@ -141,7 +140,7 @@ fn fold_block(
141140
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
142141
}.collect();
143142
let filtered_view_items = do b.view_items.iter().filter_map |a| {
144-
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
143+
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
145144
}.collect();
146145
ast::blk_ {
147146
view_items: filtered_view_items,
@@ -160,8 +159,8 @@ fn foreign_item_in_cfg(cx: @Context, item: @ast::foreign_item) -> bool {
160159
return (cx.in_cfg)(/*bad*/copy item.attrs);
161160
}
162161

163-
fn view_item_in_cfg(cx: @Context, item: @ast::view_item) -> bool {
164-
return (cx.in_cfg)(/*bad*/copy item.attrs);
162+
fn view_item_in_cfg(cx: @Context, item: &ast::view_item) -> bool {
163+
return (cx.in_cfg)(item.attrs);
165164
}
166165

167166
fn method_in_cfg(cx: @Context, meth: @ast::method) -> bool {

src/librustc/front/std_inject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
4141
let precursor = @fold::AstFoldFns {
4242
fold_crate: |crate, span, fld| {
4343
let n1 = sess.next_node_id();
44-
let vi1 = @ast::view_item {
44+
let vi1 = ast::view_item {
4545
node: ast::view_item_extern_mod(
4646
sess.ident_of("std"), ~[], n1),
4747
attrs: ~[
@@ -87,7 +87,7 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
8787
};
8888

8989
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
90-
let vi2 = @ast::view_item { node: ast::view_item_use(~[vp]),
90+
let vi2 = ast::view_item { node: ast::view_item_use(~[vp]),
9191
attrs: ~[],
9292
vis: ast::private,
9393
span: dummy_sp() };

src/librustc/front/test.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ mod __test {
272272
273273
*/
274274

275-
fn mk_std(cx: &TestCtxt) -> @ast::view_item {
275+
fn mk_std(cx: &TestCtxt) -> ast::view_item {
276276
let vers = ast::lit_str(@"0.7");
277277
let vers = nospan(vers);
278278
let mi = ast::meta_name_value(@"vers", vers);
@@ -287,13 +287,12 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
287287
ast::view_item_extern_mod(id_std, ~[@mi],
288288
cx.sess.next_node_id())
289289
};
290-
let vi = ast::view_item {
290+
ast::view_item {
291291
node: vi,
292292
attrs: ~[],
293293
vis: ast::public,
294294
span: dummy_sp()
295-
};
296-
return @vi;
295+
}
297296
}
298297

299298
fn mk_test_module(cx: &TestCtxt) -> @ast::item {

src/librustc/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn visit_crate(e: &Env, c: &ast::crate) {
136136
}
137137
}
138138

139-
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
139+
fn visit_view_item(e: @mut Env, i: &ast::view_item) {
140140
match i.node {
141141
ast::view_item_extern_mod(ident, ref meta_items, id) => {
142142
debug!("resolving extern mod stmt. ident: %?, meta: %?",

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl Resolver {
14321432
/// Constructs the reduced graph for one 'view item'. View items consist
14331433
/// of imports and use directives.
14341434
pub fn build_reduced_graph_for_view_item(@mut self,
1435-
view_item: @view_item,
1435+
view_item: &view_item,
14361436
(parent, _):
14371437
(ReducedGraphParent,
14381438
vt<ReducedGraphParent>)) {
@@ -5295,7 +5295,7 @@ impl Resolver {
52955295
visit_crate(self.crate, ((), vt));
52965296
}
52975297

5298-
pub fn check_for_item_unused_imports(&mut self, vi: @view_item) {
5298+
pub fn check_for_item_unused_imports(&mut self, vi: &view_item) {
52995299
// Ignore public import statements because there's no way to be sure
53005300
// whether they're used or not. Also ignore imports with a dummy span
53015301
// because this means that they were generated in some fashion by the

src/libsyntax/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub type blk = spanned<blk_>;
219219

220220
#[deriving(Eq, Encodable, Decodable,IterBytes)]
221221
pub struct blk_ {
222-
view_items: ~[@view_item],
222+
view_items: ~[view_item],
223223
stmts: ~[@stmt],
224224
expr: Option<@expr>,
225225
id: node_id,
@@ -827,7 +827,7 @@ pub struct method {
827827
828828
#[deriving(Eq, Encodable, Decodable,IterBytes)]
829829
pub struct _mod {
830-
view_items: ~[@view_item],
830+
view_items: ~[view_item],
831831
items: ~[@item],
832832
}
833833
@@ -839,7 +839,7 @@ pub enum foreign_mod_sort { named, anonymous }
839839
pub struct foreign_mod {
840840
sort: foreign_mod_sort,
841841
abis: AbiSet,
842-
view_items: ~[@view_item],
842+
view_items: ~[view_item],
843843
items: ~[@foreign_item],
844844
}
845845

src/libsyntax/ext/build.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub trait AstBuilder {
8080
fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::blk;
8181
fn blk_expr(&self, expr: @ast::expr) -> ast::blk;
8282
fn blk_all(&self, span: span,
83-
view_items: ~[@ast::view_item],
83+
view_items: ~[ast::view_item],
8484
stmts: ~[@ast::stmt],
8585
expr: Option<@ast::expr>) -> ast::blk;
8686

@@ -202,7 +202,7 @@ pub trait AstBuilder {
202202

203203
fn item_mod(&self, span: span,
204204
name: ident, attrs: ~[ast::attribute],
205-
vi: ~[@ast::view_item], items: ~[@ast::item]) -> @ast::item;
205+
vi: ~[ast::view_item], items: ~[@ast::item]) -> @ast::item;
206206

207207
fn item_ty_poly(&self,
208208
span: span,
@@ -218,11 +218,11 @@ pub trait AstBuilder {
218218
fn meta_name_value(&self, sp: span, name: @str, value: ast::lit_) -> @ast::meta_item;
219219

220220
fn view_use(&self, sp: span,
221-
vis: ast::visibility, vp: ~[@ast::view_path]) -> @ast::view_item;
221+
vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item;
222222
fn view_use_list(&self, sp: span, vis: ast::visibility,
223-
path: ~[ast::ident], imports: &[ast::ident]) -> @ast::view_item;
223+
path: ~[ast::ident], imports: &[ast::ident]) -> ast::view_item;
224224
fn view_use_glob(&self, sp: span,
225-
vis: ast::visibility, path: ~[ast::ident]) -> @ast::view_item;
225+
vis: ast::visibility, path: ~[ast::ident]) -> ast::view_item;
226226
}
227227

228228
impl AstBuilder for @ExtCtxt {
@@ -400,7 +400,7 @@ impl AstBuilder for @ExtCtxt {
400400
}
401401
fn blk_all(&self,
402402
span: span,
403-
view_items: ~[@ast::view_item],
403+
view_items: ~[ast::view_item],
404404
stmts: ~[@ast::stmt],
405405
expr: Option<@ast::expr>) -> ast::blk {
406406
respan(span,
@@ -762,7 +762,7 @@ impl AstBuilder for @ExtCtxt {
762762

763763
fn item_mod(&self, span: span, name: ident,
764764
attrs: ~[ast::attribute],
765-
vi: ~[@ast::view_item],
765+
vi: ~[ast::view_item],
766766
items: ~[@ast::item]) -> @ast::item {
767767
self.item(
768768
span,
@@ -804,8 +804,8 @@ impl AstBuilder for @ExtCtxt {
804804
}
805805

806806
fn view_use(&self, sp: span,
807-
vis: ast::visibility, vp: ~[@ast::view_path]) -> @ast::view_item {
808-
@ast::view_item {
807+
vis: ast::visibility, vp: ~[@ast::view_path]) -> ast::view_item {
808+
ast::view_item {
809809
node: ast::view_item_use(vp),
810810
attrs: ~[],
811811
vis: vis,
@@ -814,7 +814,7 @@ impl AstBuilder for @ExtCtxt {
814814
}
815815

816816
fn view_use_list(&self, sp: span, vis: ast::visibility,
817-
path: ~[ast::ident], imports: &[ast::ident]) -> @ast::view_item {
817+
path: ~[ast::ident], imports: &[ast::ident]) -> ast::view_item {
818818
let imports = do imports.map |id| {
819819
respan(sp, ast::path_list_ident_ { name: *id, id: self.next_id() })
820820
};
@@ -827,7 +827,7 @@ impl AstBuilder for @ExtCtxt {
827827
}
828828

829829
fn view_use_glob(&self, sp: span,
830-
vis: ast::visibility, path: ~[ast::ident]) -> @ast::view_item {
830+
vis: ast::visibility, path: ~[ast::ident]) -> ast::view_item {
831831
self.view_use(sp, vis,
832832
~[@respan(sp,
833833
ast::view_path_glob(self.path(sp, path), self.next_id()))])

src/libsyntax/fold.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use opt_vec::OptVec;
1616

1717
pub trait ast_fold {
1818
fn fold_crate(@self, &crate) -> crate;
19-
fn fold_view_item(@self, @view_item) -> @view_item;
19+
fn fold_view_item(@self, &view_item) -> view_item;
2020
fn fold_foreign_item(@self, @foreign_item) -> @foreign_item;
2121
fn fold_item(@self, @item) -> Option<@item>;
2222
fn fold_struct_field(@self, @struct_field) -> @struct_field;
@@ -372,7 +372,7 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method {
372372

373373

374374
pub fn noop_fold_block(b: &blk_, fld: @ast_fold) -> blk_ {
375-
let view_items = b.view_items.map(|x| fld.fold_view_item(*x));
375+
let view_items = b.view_items.map(|x| fld.fold_view_item(x));
376376
let mut stmts = ~[];
377377
for b.stmts.iter().advance |stmt| {
378378
match fld.fold_stmt(*stmt) {
@@ -697,7 +697,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ {
697697
// ...nor do modules
698698
pub fn noop_fold_mod(m: &_mod, fld: @ast_fold) -> _mod {
699699
ast::_mod {
700-
view_items: m.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
700+
view_items: m.view_items.iter().transform(|x| fld.fold_view_item(x)).collect(),
701701
items: m.items.iter().filter_map(|x| fld.fold_item(*x)).collect(),
702702
}
703703
}
@@ -706,7 +706,7 @@ fn noop_fold_foreign_mod(nm: &foreign_mod, fld: @ast_fold) -> foreign_mod {
706706
ast::foreign_mod {
707707
sort: nm.sort,
708708
abis: nm.abis,
709-
view_items: nm.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
709+
view_items: nm.view_items.iter().transform(|x| fld.fold_view_item(x)).collect(),
710710
items: nm.items.iter().transform(|x| fld.fold_foreign_item(*x)).collect(),
711711
}
712712
}
@@ -818,9 +818,8 @@ impl ast_fold for AstFoldFns {
818818
let (n, s) = (self.fold_crate)(&c.node, c.span, self as @ast_fold);
819819
spanned { node: n, span: (self.new_span)(s) }
820820
}
821-
fn fold_view_item(@self, x: @view_item) ->
822-
@view_item {
823-
@ast::view_item {
821+
fn fold_view_item(@self, x: &view_item) -> view_item {
822+
ast::view_item {
824823
node: (self.fold_view_item)(&x.node, self as @ast_fold),
825824
attrs: x.attrs.iter().transform(|a| fold_attribute_(*a, self as @ast_fold)).collect(),
826825
vis: x.vis,

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub enum item_or_view_item {
115115
iovi_none,
116116
iovi_item(@item),
117117
iovi_foreign_item(@foreign_item),
118-
iovi_view_item(@view_item)
118+
iovi_view_item(view_item)
119119
}
120120

121121
#[deriving(Eq)]
@@ -208,7 +208,7 @@ fn maybe_append(lhs: ~[attribute], rhs: Option<~[attribute]>)
208208

209209
struct ParsedItemsAndViewItems {
210210
attrs_remaining: ~[attribute],
211-
view_items: ~[@view_item],
211+
view_items: ~[view_item],
212212
items: ~[@item],
213213
foreign_items: ~[@foreign_item]
214214
}
@@ -4074,7 +4074,7 @@ impl Parser {
40744074
// extern mod foo;
40754075
let metadata = self.parse_optional_meta();
40764076
self.expect(&token::SEMI);
4077-
iovi_view_item(@ast::view_item {
4077+
iovi_view_item(ast::view_item {
40784078
node: view_item_extern_mod(ident, metadata, self.get_id()),
40794079
attrs: copy attrs,
40804080
vis: visibility,
@@ -4308,7 +4308,7 @@ impl Parser {
43084308
// USE ITEM (iovi_view_item)
43094309
let view_item = self.parse_use();
43104310
self.expect(&token::SEMI);
4311-
return iovi_view_item(@ast::view_item {
4311+
return iovi_view_item(ast::view_item {
43124312
node: view_item,
43134313
attrs: attrs,
43144314
vis: visibility,
@@ -4656,7 +4656,7 @@ impl Parser {
46564656
&self,
46574657
attrs: ~[attribute],
46584658
vis: visibility
4659-
) -> @view_item {
4659+
) -> view_item {
46604660
let lo = self.span.lo;
46614661
let node = if self.eat_keyword(keywords::Use) {
46624662
self.parse_use()
@@ -4669,7 +4669,7 @@ impl Parser {
46694669
self.bug("expected view item");
46704670
};
46714671
self.expect(&token::SEMI);
4672-
@ast::view_item { node: node,
4672+
ast::view_item { node: node,
46734673
attrs: attrs,
46744674
vis: vis,
46754675
span: mk_sp(lo, self.last_span.hi) }
@@ -4687,7 +4687,7 @@ impl Parser {
46874687
let mut attrs = vec::append(first_item_attrs,
46884688
self.parse_outer_attributes());
46894689
// First, parse view items.
4690-
let mut view_items = ~[];
4690+
let mut view_items : ~[ast::view_item] = ~[];
46914691
let mut items = ~[];
46924692
let mut done = false;
46934693
// I think this code would probably read better as a single

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub fn commasep_exprs(s: @ps, b: breaks, exprs: &[@ast::expr]) {
352352
pub fn print_mod(s: @ps, _mod: &ast::_mod, attrs: &[ast::attribute]) {
353353
print_inner_attributes(s, attrs);
354354
for _mod.view_items.iter().advance |vitem| {
355-
print_view_item(s, *vitem);
355+
print_view_item(s, vitem);
356356
}
357357
for _mod.items.iter().advance |item| { print_item(s, *item); }
358358
}
@@ -361,7 +361,7 @@ pub fn print_foreign_mod(s: @ps, nmod: &ast::foreign_mod,
361361
attrs: &[ast::attribute]) {
362362
print_inner_attributes(s, attrs);
363363
for nmod.view_items.iter().advance |vitem| {
364-
print_view_item(s, *vitem);
364+
print_view_item(s, vitem);
365365
}
366366
for nmod.items.iter().advance |item| { print_foreign_item(s, *item); }
367367
}
@@ -947,7 +947,7 @@ pub fn print_possibly_embedded_block_(s: @ps,
947947

948948
print_inner_attributes(s, attrs);
949949

950-
for blk.node.view_items.iter().advance |vi| { print_view_item(s, *vi); }
950+
for blk.node.view_items.iter().advance |vi| { print_view_item(s, vi); }
951951
for blk.node.stmts.iter().advance |st| {
952952
print_stmt(s, *st);
953953
}
@@ -1844,7 +1844,7 @@ pub fn print_view_paths(s: @ps, vps: &[@ast::view_path]) {
18441844
commasep(s, inconsistent, vps, print_view_path);
18451845
}
18461846

1847-
pub fn print_view_item(s: @ps, item: @ast::view_item) {
1847+
pub fn print_view_item(s: @ps, item: &ast::view_item) {
18481848
hardbreak_if_not_bol(s);
18491849
maybe_print_comment(s, item.span.lo);
18501850
print_outer_attributes(s, item.attrs);

0 commit comments

Comments
 (0)