rustc::metadata::decoder: cleanup and slightly speed up each_path

This commit is contained in:
Philipp Brüschweiler 2013-06-05 13:29:22 +02:00
parent 4abd83b18d
commit 9b3743938d
1 changed files with 65 additions and 77 deletions

View File

@ -476,22 +476,21 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) -> bool {
}
/// Iterates over all the paths in the given crate.
pub fn _each_path(intr: @ident_interner,
pub fn each_path(intr: @ident_interner,
cdata: cmd,
get_crate_data: GetCrateDataCb,
f: &fn(&str, def_like, ast::visibility) -> bool)
-> bool {
// FIXME #4572: This function needs to be nuked, as it's impossible to make fast.
// It's the source of most of the performance problems when compiling small crates.
let root = reader::Doc(cdata.data);
let items = reader::get_doc(root, tag_items);
let items_data = reader::get_doc(items, tag_items_data);
let mut broken = false;
// First, go through all the explicit items.
for reader::tagged_docs(items_data, tag_items_data_item) |item_doc| {
if !broken {
let path = ast_map::path_to_str_with_sep(
item_path(item_doc), "::", intr);
let path = ast_map::path_to_str(item_path(item_doc), intr);
let path_is_empty = path.is_empty();
if !path_is_empty {
// Extract the def ID.
@ -505,13 +504,12 @@ pub fn _each_path(intr: @ident_interner,
// Hand the information off to the iteratee.
if !f(path, def_like, vis) {
broken = true; // FIXME #4572: This is awful.
return false;
}
}
// If this is a module, find the reexports.
for each_reexport(item_doc) |reexport_doc| {
if !broken {
let def_id_doc =
reader::get_doc(reexport_doc,
tag_items_data_item_reexport_def_id);
@ -555,24 +553,14 @@ pub fn _each_path(intr: @ident_interner,
item: %s", reexport_path);
if (!f(reexport_path, def_like, ast::public)) {
broken = true; // FIXME #4572: This is awful.
}
}
return false;
}
}
}
}
}
return broken;
}
pub fn each_path(intr: @ident_interner,
cdata: cmd,
get_crate_data: GetCrateDataCb,
f: &fn(&str, def_like, ast::visibility) -> bool)
-> bool {
_each_path(intr, cdata, get_crate_data, f)
return true;
}
pub fn get_item_path(cdata: cmd, id: ast::node_id)