rustc::metadata::decoder: cleanup and slightly speed up each_path
This commit is contained in:
parent
4abd83b18d
commit
9b3743938d
1 changed files with 65 additions and 77 deletions
|
@ -476,103 +476,91 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterates over all the paths in the given crate.
|
/// 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,
|
cdata: cmd,
|
||||||
get_crate_data: GetCrateDataCb,
|
get_crate_data: GetCrateDataCb,
|
||||||
f: &fn(&str, def_like, ast::visibility) -> bool)
|
f: &fn(&str, def_like, ast::visibility) -> bool)
|
||||||
-> 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 root = reader::Doc(cdata.data);
|
||||||
let items = reader::get_doc(root, tag_items);
|
let items = reader::get_doc(root, tag_items);
|
||||||
let items_data = reader::get_doc(items, tag_items_data);
|
let items_data = reader::get_doc(items, tag_items_data);
|
||||||
|
|
||||||
let mut broken = false;
|
|
||||||
|
|
||||||
// First, go through all the explicit items.
|
// First, go through all the explicit items.
|
||||||
for reader::tagged_docs(items_data, tag_items_data_item) |item_doc| {
|
for reader::tagged_docs(items_data, tag_items_data_item) |item_doc| {
|
||||||
if !broken {
|
let path = ast_map::path_to_str(item_path(item_doc), intr);
|
||||||
let path = ast_map::path_to_str_with_sep(
|
let path_is_empty = path.is_empty();
|
||||||
item_path(item_doc), "::", intr);
|
if !path_is_empty {
|
||||||
let path_is_empty = path.is_empty();
|
// Extract the def ID.
|
||||||
if !path_is_empty {
|
let def_id = item_def_id(item_doc, cdata);
|
||||||
// Extract the def ID.
|
|
||||||
let def_id = item_def_id(item_doc, cdata);
|
|
||||||
|
|
||||||
// Construct the def for this item.
|
// Construct the def for this item.
|
||||||
debug!("(each_path) yielding explicit item: %s", path);
|
debug!("(each_path) yielding explicit item: %s", path);
|
||||||
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
|
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
|
||||||
|
|
||||||
let vis = item_visibility(item_doc);
|
let vis = item_visibility(item_doc);
|
||||||
|
|
||||||
// Hand the information off to the iteratee.
|
// Hand the information off to the iteratee.
|
||||||
if !f(path, def_like, vis) {
|
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| {
|
||||||
|
let def_id_doc =
|
||||||
|
reader::get_doc(reexport_doc,
|
||||||
|
tag_items_data_item_reexport_def_id);
|
||||||
|
let def_id =
|
||||||
|
reader::with_doc_data(def_id_doc,
|
||||||
|
|d| parse_def_id(d));
|
||||||
|
let def_id = translate_def_id(cdata, def_id);
|
||||||
|
|
||||||
|
let reexport_name_doc =
|
||||||
|
reader::get_doc(reexport_doc,
|
||||||
|
tag_items_data_item_reexport_name);
|
||||||
|
let reexport_name = reader::doc_as_str(reexport_name_doc);
|
||||||
|
|
||||||
|
let reexport_path;
|
||||||
|
if path_is_empty {
|
||||||
|
reexport_path = reexport_name;
|
||||||
|
} else {
|
||||||
|
reexport_path = path + "::" + reexport_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a module, find the reexports.
|
// This reexport may be in yet another crate
|
||||||
for each_reexport(item_doc) |reexport_doc| {
|
let other_crates_items = if def_id.crate == cdata.cnum {
|
||||||
if !broken {
|
items
|
||||||
let def_id_doc =
|
} else {
|
||||||
reader::get_doc(reexport_doc,
|
let crate_data = get_crate_data(def_id.crate);
|
||||||
tag_items_data_item_reexport_def_id);
|
let root = reader::Doc(crate_data.data);
|
||||||
let def_id =
|
reader::get_doc(root, tag_items)
|
||||||
reader::with_doc_data(def_id_doc,
|
};
|
||||||
|d| parse_def_id(d));
|
|
||||||
let def_id = translate_def_id(cdata, def_id);
|
|
||||||
|
|
||||||
let reexport_name_doc =
|
// Get the item.
|
||||||
reader::get_doc(reexport_doc,
|
match maybe_find_item(def_id.node, other_crates_items) {
|
||||||
tag_items_data_item_reexport_name);
|
None => {}
|
||||||
let reexport_name = reader::doc_as_str(reexport_name_doc);
|
Some(item_doc) => {
|
||||||
|
// Construct the def for this item.
|
||||||
|
let def_like = item_to_def_like(item_doc,
|
||||||
|
def_id,
|
||||||
|
cdata.cnum);
|
||||||
|
|
||||||
let reexport_path;
|
// Hand the information off to the iteratee.
|
||||||
if path_is_empty {
|
debug!("(each_path) yielding reexported \
|
||||||
reexport_path = reexport_name;
|
item: %s", reexport_path);
|
||||||
} else {
|
|
||||||
reexport_path = path + "::" + reexport_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This reexport may be in yet another crate
|
if (!f(reexport_path, def_like, ast::public)) {
|
||||||
let other_crates_items = if def_id.crate == cdata.cnum {
|
return false;
|
||||||
items
|
|
||||||
} else {
|
|
||||||
let crate_data = get_crate_data(def_id.crate);
|
|
||||||
let root = reader::Doc(crate_data.data);
|
|
||||||
reader::get_doc(root, tag_items)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get the item.
|
|
||||||
match maybe_find_item(def_id.node, other_crates_items) {
|
|
||||||
None => {}
|
|
||||||
Some(item_doc) => {
|
|
||||||
// Construct the def for this item.
|
|
||||||
let def_like = item_to_def_like(item_doc,
|
|
||||||
def_id,
|
|
||||||
cdata.cnum);
|
|
||||||
|
|
||||||
// Hand the information off to the iteratee.
|
|
||||||
debug!("(each_path) yielding reexported \
|
|
||||||
item: %s", reexport_path);
|
|
||||||
|
|
||||||
if (!f(reexport_path, def_like, ast::public)) {
|
|
||||||
broken = true; // FIXME #4572: This is awful.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return broken;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item_path(cdata: cmd, id: ast::node_id)
|
pub fn get_item_path(cdata: cmd, id: ast::node_id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue