Skip to content

Commit af863cf

Browse files
committed
auto merge of #6946 : Blei/rust/fix-each-path, r=Aatch
2 parents 4abd83b + 9b37439 commit af863cf

File tree

1 file changed

+70
-82
lines changed

1 file changed

+70
-82
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 70 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -476,103 +476,91 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) -> bool {
476476
}
477477

478478
/// Iterates over all the paths in the given crate.
479-
pub fn _each_path(intr: @ident_interner,
480-
cdata: cmd,
481-
get_crate_data: GetCrateDataCb,
482-
f: &fn(&str, def_like, ast::visibility) -> bool)
483-
-> bool {
479+
pub fn each_path(intr: @ident_interner,
480+
cdata: cmd,
481+
get_crate_data: GetCrateDataCb,
482+
f: &fn(&str, def_like, ast::visibility) -> bool)
483+
-> bool {
484+
// FIXME #4572: This function needs to be nuked, as it's impossible to make fast.
485+
// It's the source of most of the performance problems when compiling small crates.
486+
484487
let root = reader::Doc(cdata.data);
485488
let items = reader::get_doc(root, tag_items);
486489
let items_data = reader::get_doc(items, tag_items_data);
487490

488-
let mut broken = false;
489-
490491
// First, go through all the explicit items.
491492
for reader::tagged_docs(items_data, tag_items_data_item) |item_doc| {
492-
if !broken {
493-
let path = ast_map::path_to_str_with_sep(
494-
item_path(item_doc), "::", intr);
495-
let path_is_empty = path.is_empty();
496-
if !path_is_empty {
497-
// Extract the def ID.
498-
let def_id = item_def_id(item_doc, cdata);
499-
500-
// Construct the def for this item.
501-
debug!("(each_path) yielding explicit item: %s", path);
502-
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
503-
504-
let vis = item_visibility(item_doc);
505-
506-
// Hand the information off to the iteratee.
507-
if !f(path, def_like, vis) {
508-
broken = true; // FIXME #4572: This is awful.
509-
}
493+
let path = ast_map::path_to_str(item_path(item_doc), intr);
494+
let path_is_empty = path.is_empty();
495+
if !path_is_empty {
496+
// Extract the def ID.
497+
let def_id = item_def_id(item_doc, cdata);
498+
499+
// Construct the def for this item.
500+
debug!("(each_path) yielding explicit item: %s", path);
501+
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
502+
503+
let vis = item_visibility(item_doc);
504+
505+
// Hand the information off to the iteratee.
506+
if !f(path, def_like, vis) {
507+
return false;
510508
}
509+
}
511510

512-
// If this is a module, find the reexports.
513-
for each_reexport(item_doc) |reexport_doc| {
514-
if !broken {
515-
let def_id_doc =
516-
reader::get_doc(reexport_doc,
517-
tag_items_data_item_reexport_def_id);
518-
let def_id =
519-
reader::with_doc_data(def_id_doc,
520-
|d| parse_def_id(d));
521-
let def_id = translate_def_id(cdata, def_id);
522-
523-
let reexport_name_doc =
524-
reader::get_doc(reexport_doc,
525-
tag_items_data_item_reexport_name);
526-
let reexport_name = reader::doc_as_str(reexport_name_doc);
527-
528-
let reexport_path;
529-
if path_is_empty {
530-
reexport_path = reexport_name;
531-
} else {
532-
reexport_path = path + "::" + reexport_name;
533-
}
511+
// If this is a module, find the reexports.
512+
for each_reexport(item_doc) |reexport_doc| {
513+
let def_id_doc =
514+
reader::get_doc(reexport_doc,
515+
tag_items_data_item_reexport_def_id);
516+
let def_id =
517+
reader::with_doc_data(def_id_doc,
518+
|d| parse_def_id(d));
519+
let def_id = translate_def_id(cdata, def_id);
520+
521+
let reexport_name_doc =
522+
reader::get_doc(reexport_doc,
523+
tag_items_data_item_reexport_name);
524+
let reexport_name = reader::doc_as_str(reexport_name_doc);
525+
526+
let reexport_path;
527+
if path_is_empty {
528+
reexport_path = reexport_name;
529+
} else {
530+
reexport_path = path + "::" + reexport_name;
531+
}
534532

535-
// This reexport may be in yet another crate
536-
let other_crates_items = if def_id.crate == cdata.cnum {
537-
items
538-
} else {
539-
let crate_data = get_crate_data(def_id.crate);
540-
let root = reader::Doc(crate_data.data);
541-
reader::get_doc(root, tag_items)
542-
};
543-
544-
// Get the item.
545-
match maybe_find_item(def_id.node, other_crates_items) {
546-
None => {}
547-
Some(item_doc) => {
548-
// Construct the def for this item.
549-
let def_like = item_to_def_like(item_doc,
550-
def_id,
551-
cdata.cnum);
552-
553-
// Hand the information off to the iteratee.
554-
debug!("(each_path) yielding reexported \
555-
item: %s", reexport_path);
556-
557-
if (!f(reexport_path, def_like, ast::public)) {
558-
broken = true; // FIXME #4572: This is awful.
559-
}
560-
}
533+
// This reexport may be in yet another crate
534+
let other_crates_items = if def_id.crate == cdata.cnum {
535+
items
536+
} else {
537+
let crate_data = get_crate_data(def_id.crate);
538+
let root = reader::Doc(crate_data.data);
539+
reader::get_doc(root, tag_items)
540+
};
541+
542+
// Get the item.
543+
match maybe_find_item(def_id.node, other_crates_items) {
544+
None => {}
545+
Some(item_doc) => {
546+
// Construct the def for this item.
547+
let def_like = item_to_def_like(item_doc,
548+
def_id,
549+
cdata.cnum);
550+
551+
// Hand the information off to the iteratee.
552+
debug!("(each_path) yielding reexported \
553+
item: %s", reexport_path);
554+
555+
if (!f(reexport_path, def_like, ast::public)) {
556+
return false;
561557
}
562558
}
563559
}
564560
}
565561
}
566562

567-
return broken;
568-
}
569-
570-
pub fn each_path(intr: @ident_interner,
571-
cdata: cmd,
572-
get_crate_data: GetCrateDataCb,
573-
f: &fn(&str, def_like, ast::visibility) -> bool)
574-
-> bool {
575-
_each_path(intr, cdata, get_crate_data, f)
563+
return true;
576564
}
577565

578566
pub fn get_item_path(cdata: cmd, id: ast::node_id)

0 commit comments

Comments
 (0)