Skip to content

Commit f19e168

Browse files
committed
syntax/rustc: Less copy
1 parent 5ff6bee commit f19e168

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/librustc/middle/astencode.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,13 @@ fn decode_inlined_item(cdata: cstore::crate_metadata,
133133
to_id_range: to_id_range});
134134
let raw_ii = decode_ast(ast_doc);
135135
let ii = renumber_ast(xcx, raw_ii);
136-
// XXX: Bad copy of `path`.
137-
ast_map::map_decoded_item(tcx.sess.diagnostic(),
138-
dcx.tcx.items, copy path, ii);
139136
debug!("Fn named: %s", tcx.sess.str_of(ii.ident()));
140-
decode_side_tables(xcx, ast_doc);
141137
debug!("< Decoded inlined fn: %s::%s",
142138
ast_map::path_to_str(path, tcx.sess.parse_sess.interner),
143139
tcx.sess.str_of(ii.ident()));
140+
ast_map::map_decoded_item(tcx.sess.diagnostic(),
141+
dcx.tcx.items, path, ii);
142+
decode_side_tables(xcx, ast_doc);
144143
match ii {
145144
ast::ii_item(i) => {
146145
debug!(">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<",
@@ -309,10 +308,13 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
309308
ast::stmt_mac(*) => fail ~"unexpanded macro in astencode"
310309
}
311310
};
312-
// XXX: Bad copy.
313311
let blk_sans_items = ast::blk_ {
312+
view_items: ~[], // I don't know if we need the view_items here,
313+
// but it doesn't break tests!
314314
stmts: stmts_sans_items,
315-
.. copy blk
315+
expr: blk.expr,
316+
id: blk.id,
317+
rules: blk.rules
316318
};
317319
fold::noop_fold_block(blk_sans_items, fld)
318320
}
@@ -592,7 +594,7 @@ fn encode_vtable_res(ecx: @e::encode_ctxt,
592594
// ty::t doesn't work, and there is no way (atm) to have
593595
// hand-written encoding routines combine with auto-generated
594596
// ones. perhaps we should fix this.
595-
do ebml_w.emit_from_vec(/*bad*/copy *dr) |vtable_origin| {
597+
do ebml_w.emit_from_vec(*dr) |vtable_origin| {
596598
encode_vtable_origin(ecx, ebml_w, *vtable_origin)
597599
}
598600
}
@@ -742,8 +744,7 @@ impl writer::Encoder: ebml_writer_helpers {
742744
}
743745

744746
fn emit_tys(ecx: @e::encode_ctxt, tys: ~[ty::t]) {
745-
// XXX: Bad copy.
746-
do self.emit_from_vec(copy tys) |ty| {
747+
do self.emit_from_vec(tys) |ty| {
747748
self.emit_ty(ecx, *ty)
748749
}
749750
}
@@ -756,8 +757,8 @@ impl writer::Encoder: ebml_writer_helpers {
756757

757758
fn emit_tpbt(ecx: @e::encode_ctxt, tpbt: ty::ty_param_bounds_and_ty) {
758759
do self.emit_rec {
759-
do self.emit_field(~"bounds", 0u) {
760-
do self.emit_from_vec(/*bad*/copy *tpbt.bounds) |bs| {
760+
do self.emit_field(~"bounds", 0) {
761+
do self.emit_from_vec(*tpbt.bounds) |bs| {
761762
self.emit_bounds(ecx, *bs);
762763
}
763764
}
@@ -840,7 +841,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
840841
do ebml_w.tag(c::tag_table_freevars) {
841842
ebml_w.id(id);
842843
do ebml_w.tag(c::tag_table_val) {
843-
do ebml_w.emit_from_vec(/*bad*/copy **fv) |fv_entry| {
844+
do ebml_w.emit_from_vec(**fv) |fv_entry| {
844845
encode_freevar_entry(ebml_w, *fv_entry)
845846
}
846847
}

src/libstd/serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ pub impl<
566566
// In some cases, these should eventually be coded as traits.
567567

568568
pub trait EncoderHelpers {
569-
fn emit_from_vec<T>(&self, v: ~[T], f: fn(v: &T));
569+
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T));
570570
}
571571

572572
pub impl<S: Encoder> S: EncoderHelpers {
573-
fn emit_from_vec<T>(&self, v: ~[T], f: fn(v: &T)) {
573+
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T)) {
574574
do self.emit_owned_vec(v.len()) {
575575
for v.eachi |i, e| {
576576
do self.emit_vec_elt(i) {

src/libsyntax/ast_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn map_crate(diag: span_handler, c: crate) -> map {
149149
// crate. The `path` should be the path to the item but should not include
150150
// the item itself.
151151
fn map_decoded_item(diag: span_handler,
152-
map: map, +path: path, ii: inlined_item) {
152+
map: map, path: path, ii: inlined_item) {
153153
// I believe it is ok for the local IDs of inlined items from other crates
154154
// to overlap with the local ids from this crate, so just generate the ids
155155
// starting from 0. (In particular, I think these ids are only used in
@@ -158,8 +158,8 @@ fn map_decoded_item(diag: span_handler,
158158
// variables that are simultaneously in scope).
159159
let cx = ctx {
160160
map: map,
161-
mut path: /* FIXME (#2543) */ copy path,
162-
mut local_id: 0u,
161+
mut path: path,
162+
mut local_id: 0,
163163
diag: diag,
164164
};
165165
let v = mk_ast_map_visitor();

0 commit comments

Comments
 (0)