Skip to content

Commit d3bb499

Browse files
committed
rustc: Make metadata::encoder::encode_path take an &path
Eliminates some bad copies.
1 parent 012364b commit d3bb499

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Encoder,
298298
disr_val = vi[i].disr_val;
299299
}
300300
encode_type_param_bounds(ebml_w, ecx, /*bad*/copy ty_params);
301-
encode_path(ecx, ebml_w, /*bad*/copy path,
301+
encode_path(ecx, ebml_w, &path,
302302
ast_map::path_name(variant.node.name));
303303
ebml_w.end_tag();
304304
disr_val += 1;
@@ -307,7 +307,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Encoder,
307307
}
308308

309309
fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Encoder,
310-
path: ast_map::path, name: ast_map::path_elt) {
310+
path: &ast_map::path, name: ast_map::path_elt) {
311311
fn encode_path_elt(ecx: @encode_ctxt, ebml_w: writer::Encoder,
312312
elt: ast_map::path_elt) {
313313
let (tag, name) = match elt {
@@ -319,8 +319,8 @@ fn encode_path(ecx: @encode_ctxt, ebml_w: writer::Encoder,
319319
}
320320

321321
do ebml_w.wr_tag(tag_path) {
322-
ebml_w.wr_tagged_u32(tag_path_len, (vec::len(path) + 1u) as u32);
323-
for vec::each(path) |pe| {
322+
ebml_w.wr_tagged_u32(tag_path_len, (path.len() + 1) as u32);
323+
for path.each |pe| {
324324
encode_path_elt(ecx, ebml_w, *pe);
325325
}
326326
encode_path_elt(ecx, ebml_w, name);
@@ -353,11 +353,11 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
353353
ebml_w.wr_str(def_to_str(local_def(did)));
354354
ebml_w.end_tag();
355355
}
356-
_ => {} // XXX: Encode these too.
356+
_ => {} // FIXME #4573: Encode these too.
357357
}
358358
}
359359

360-
encode_path(ecx, ebml_w, path, ast_map::path_mod(name));
360+
encode_path(ecx, ebml_w, &path, ast_map::path_mod(name));
361361

362362
// Encode the reexports of this module.
363363
debug!("(encoding info for module) encoding reexports for %d", id);
@@ -455,8 +455,7 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
455455
tcx.sess.str_of(nm), id);
456456
encode_visibility(ebml_w, vis);
457457
encode_name(ecx, ebml_w, nm);
458-
encode_path(ecx, ebml_w, /*bad*/copy path,
459-
ast_map::path_name(nm));
458+
encode_path(ecx, ebml_w, &path, ast_map::path_name(nm));
460459
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
461460
encode_mutability(ebml_w, mt);
462461
encode_def_id(ebml_w, local_def(id));
@@ -482,8 +481,7 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Encoder,
482481
ecx.tcx.sess.str_of(ident),
483482
ty_to_str(ecx.tcx, its_ty), id);
484483
encode_type(ecx, ebml_w, its_ty);
485-
// XXX: Bad copy.
486-
encode_path(ecx, ebml_w, copy path, ast_map::path_name(ident));
484+
encode_path(ecx, ebml_w, &path, ast_map::path_name(ident));
487485
match item {
488486
Some(ref it) => {
489487
(ecx.encode_inlined_item)(ecx, ebml_w, path, (*it));
@@ -516,8 +514,7 @@ fn encode_info_for_method(ecx: @encode_ctxt,
516514
encode_type_param_bounds(ebml_w, ecx, all_tps);
517515
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, m.id));
518516
encode_name(ecx, ebml_w, m.ident);
519-
// XXX: Bad copy.
520-
encode_path(ecx, ebml_w, copy impl_path, ast_map::path_name(m.ident));
517+
encode_path(ecx, ebml_w, &impl_path, ast_map::path_name(m.ident));
521518
encode_self_type(ebml_w, m.self_ty.node);
522519
if len > 0u || should_inline {
523520
(ecx.encode_inlined_item)(
@@ -585,7 +582,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
585582
encode_family(ebml_w, 'c');
586583
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
587584
encode_symbol(ecx, ebml_w, item.id);
588-
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
585+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
589586
ebml_w.end_tag();
590587
}
591588
item_fn(_, purity, tps, _) => {
@@ -596,8 +593,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
596593
let tps_len = tps.len();
597594
encode_type_param_bounds(ebml_w, ecx, tps);
598595
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
599-
// XXX: Bad copy.
600-
encode_path(ecx, ebml_w, copy path, ast_map::path_name(item.ident));
596+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
601597
encode_attributes(ebml_w, /*bad*/copy item.attrs);
602598
if tps_len > 0u || should_inline(item.attrs) {
603599
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
@@ -616,7 +612,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
616612
encode_def_id(ebml_w, local_def(item.id));
617613
encode_family(ebml_w, 'n');
618614
encode_name(ecx, ebml_w, item.ident);
619-
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
615+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
620616
ebml_w.end_tag();
621617
}
622618
item_ty(_, tps) => {
@@ -627,7 +623,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
627623
encode_type_param_bounds(ebml_w, ecx, tps);
628624
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
629625
encode_name(ecx, ebml_w, item.ident);
630-
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
626+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
631627
encode_region_param(ecx, ebml_w, item);
632628
ebml_w.end_tag();
633629
}
@@ -644,8 +640,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
644640
}
645641
(ecx.encode_inlined_item)(ecx, ebml_w, /*bad*/copy path,
646642
ii_item(item));
647-
encode_path(ecx, ebml_w, /*bad*/copy path,
648-
ast_map::path_name(item.ident));
643+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
649644
encode_region_param(ecx, ebml_w, item);
650645
}
651646
encode_enum_variant_info(ecx,
@@ -686,7 +681,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
686681
encode_type_param_bounds(ebml_w, ecx, tps);
687682
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
688683
encode_name(ecx, ebml_w, item.ident);
689-
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
684+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
690685
encode_region_param(ecx, ebml_w, item);
691686
/* Encode the dtor */
692687
/* Encode id for dtor */
@@ -744,8 +739,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
744739
do opt_trait.iter() |associated_trait| {
745740
encode_trait_ref(ebml_w, ecx, *associated_trait);
746741
}
747-
// XXX: Bad copy.
748-
encode_path(ecx, ebml_w, copy path, ast_map::path_name(item.ident));
742+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
749743
ebml_w.end_tag();
750744

751745
let impl_path = vec::append_one(path,
@@ -801,8 +795,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
801795
}
802796
i += 1u;
803797
}
804-
// XXX: Bad copy.
805-
encode_path(ecx, ebml_w, copy path, ast_map::path_name(item.ident));
798+
encode_path(ecx, ebml_w, &path, ast_map::path_name(item.ident));
806799
for traits.each |associated_trait| {
807800
encode_trait_ref(ebml_w, ecx, *associated_trait)
808801
}
@@ -830,7 +823,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
830823
encode_type(ecx, ebml_w, polyty.ty);
831824
let m_path = vec::append_one(/*bad*/copy path,
832825
ast_map::path_name(item.ident));
833-
encode_path(ecx, ebml_w, m_path, ast_map::path_name(ty_m.ident));
826+
encode_path(ecx, ebml_w, &m_path, ast_map::path_name(ty_m.ident));
834827
ebml_w.end_tag();
835828
}
836829

@@ -868,14 +861,14 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt,
868861
} else {
869862
encode_symbol(ecx, ebml_w, nitem.id);
870863
}
871-
encode_path(ecx, ebml_w, path, ast_map::path_name(nitem.ident));
864+
encode_path(ecx, ebml_w, &path, ast_map::path_name(nitem.ident));
872865
}
873866
foreign_item_const(*) => {
874867
encode_def_id(ebml_w, local_def(nitem.id));
875868
encode_family(ebml_w, 'c');
876869
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
877870
encode_symbol(ecx, ebml_w, nitem.id);
878-
encode_path(ecx, ebml_w, path, ast_map::path_name(nitem.ident));
871+
encode_path(ecx, ebml_w, &path, ast_map::path_name(nitem.ident));
879872
}
880873
}
881874
ebml_w.end_tag();

0 commit comments

Comments
 (0)