Skip to content

Commit fcad49e

Browse files
author
Ariel Ben-Yehuda
committed
remove totally useless struct-field index
1 parent 1661947 commit fcad49e

File tree

1 file changed

+34
-46
lines changed

1 file changed

+34
-46
lines changed

src/librustc/metadata/encoder.rs

+34-46
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
287287
for variant in &def.variants {
288288
let vid = variant.did;
289289
assert!(vid.is_local());
290+
291+
if let ty::VariantKind::Dict = variant.kind() {
292+
// tuple-like enum variant fields aren't really items so
293+
// don't try to encode them.
294+
for field in &variant.fields {
295+
encode_field(ecx, rbml_w, field, index);
296+
}
297+
}
298+
290299
index.push(entry {
291300
val: vid.node as i64,
292301
pos: rbml_w.mark_stable_position(),
@@ -308,11 +317,6 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
308317
let stab = stability::lookup(ecx.tcx, vid);
309318
encode_stability(rbml_w, stab);
310319

311-
if let ty::VariantKind::Dict = variant.kind() {
312-
let idx = encode_info_for_struct(ecx, rbml_w, variant, index);
313-
encode_index(rbml_w, idx, write_i64);
314-
}
315-
316320
encode_struct_fields(rbml_w, variant, vid);
317321

318322
let specified_disr_val = variant.disr_val;
@@ -618,41 +622,29 @@ fn encode_provided_source(rbml_w: &mut Encoder,
618622
}
619623
}
620624

621-
/* Returns an index of items in this class */
622-
fn encode_info_for_struct<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
623-
rbml_w: &mut Encoder,
624-
variant: ty::VariantDef<'tcx>,
625-
global_index: &mut Vec<entry<i64>>)
626-
-> Vec<entry<i64>> {
627-
/* Each class has its own index, since different classes
628-
may have fields with the same name */
629-
let mut index = Vec::new();
630-
/* We encode both private and public fields -- need to include
631-
private fields to get the offsets right */
632-
for field in &variant.fields {
633-
let nm = field.name;
634-
let id = field.did.node;
635-
636-
let pos = rbml_w.mark_stable_position();
637-
index.push(entry {val: id as i64, pos: pos});
638-
global_index.push(entry {
639-
val: id as i64,
640-
pos: pos,
641-
});
642-
rbml_w.start_tag(tag_items_data_item);
643-
debug!("encode_info_for_struct: doing {} {}",
644-
nm, id);
645-
encode_struct_field_family(rbml_w, field.vis);
646-
encode_name(rbml_w, nm);
647-
encode_bounds_and_type_for_item(rbml_w, ecx, id);
648-
encode_def_id(rbml_w, DefId::local(id));
649-
650-
let stab = stability::lookup(ecx.tcx, field.did);
651-
encode_stability(rbml_w, stab);
625+
fn encode_field<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
626+
rbml_w: &mut Encoder,
627+
field: ty::FieldDef<'tcx>,
628+
global_index: &mut Vec<entry<i64>>) {
629+
let nm = field.name;
630+
let id = field.did.node;
652631

653-
rbml_w.end_tag();
654-
}
655-
index
632+
let pos = rbml_w.mark_stable_position();
633+
global_index.push(entry {
634+
val: id as i64,
635+
pos: pos,
636+
});
637+
rbml_w.start_tag(tag_items_data_item);
638+
debug!("encode_field: encoding {} {}", nm, id);
639+
encode_struct_field_family(rbml_w, field.vis);
640+
encode_name(rbml_w, nm);
641+
encode_bounds_and_type_for_item(rbml_w, ecx, id);
642+
encode_def_id(rbml_w, DefId::local(id));
643+
644+
let stab = stability::lookup(ecx.tcx, field.did);
645+
encode_stability(rbml_w, stab);
646+
647+
rbml_w.end_tag();
656648
}
657649

658650
fn encode_info_for_struct_ctor(ecx: &EncodeContext,
@@ -1146,11 +1138,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
11461138
let def = ecx.tcx.lookup_adt_def(def_id);
11471139
let variant = def.struct_variant();
11481140

1149-
/* First, encode the fields
1150-
These come first because we need to write them to make
1151-
the index, and the index needs to be in the item for the
1152-
class itself */
1153-
let idx = encode_info_for_struct(ecx, rbml_w, variant, index);
1141+
for field in &variant.fields {
1142+
encode_field(ecx, rbml_w, field, index);
1143+
}
11541144

11551145
/* Index the class*/
11561146
add_to_index(item, rbml_w, index);
@@ -1179,8 +1169,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
11791169
// Encode inherent implementations for this structure.
11801170
encode_inherent_implementations(ecx, rbml_w, def_id);
11811171

1182-
/* Each class has its own index -- encode it */
1183-
encode_index(rbml_w, idx, write_i64);
11841172
rbml_w.end_tag();
11851173

11861174
// If this is a tuple-like struct, encode the type of the constructor.

0 commit comments

Comments
 (0)