about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Brüschweiler <blei42@gmail.com>2013-06-05 13:29:22 +0200
committerPhilipp Brüschweiler <blei42@gmail.com>2013-06-07 10:00:48 +0200
commit9b3743938d2dde1f33ddfba71ff3f5b79a0559dd (patch)
tree39a5a4df189a93500d788efed44b67859c4a92aa
parent4abd83b18d5dffc8c2f3d827c333447c028998a0 (diff)
downloadrust-9b3743938d2dde1f33ddfba71ff3f5b79a0559dd.tar.gz
rust-9b3743938d2dde1f33ddfba71ff3f5b79a0559dd.zip
rustc::metadata::decoder: cleanup and slightly speed up each_path
-rw-r--r--src/librustc/metadata/decoder.rs152
1 files changed, 70 insertions, 82 deletions
diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs
index a6af5ca6e36..5fa678e6121 100644
--- a/src/librustc/metadata/decoder.rs
+++ b/src/librustc/metadata/decoder.rs
@@ -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.
-pub fn _each_path(intr: @ident_interner,
-                  cdata: cmd,
-                  get_crate_data: GetCrateDataCb,
-                  f: &fn(&str, def_like, ast::visibility) -> bool)
-                  -> bool {
+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_is_empty = path.is_empty();
-            if !path_is_empty {
-                // Extract the def ID.
-                let def_id = item_def_id(item_doc, cdata);
-
-                // Construct the def for this item.
-                debug!("(each_path) yielding explicit item: %s", path);
-                let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
-
-                let vis = item_visibility(item_doc);
-
-                // Hand the information off to the iteratee.
-                if !f(path, def_like, vis) {
-                    broken = true;      // FIXME #4572: This is awful.
-                }
+        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.
+            let def_id = item_def_id(item_doc, cdata);
+
+            // Construct the def for this item.
+            debug!("(each_path) yielding explicit item: %s", path);
+            let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
+
+            let vis = item_visibility(item_doc);
+
+            // Hand the information off to the iteratee.
+            if !f(path, def_like, vis) {
+                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);
-                    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.
+        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;
+            }
 
-                    // This reexport may be in yet another crate
-                    let other_crates_items = if def_id.crate == cdata.cnum {
-                        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.
-                            }
-                        }
+            // This reexport may be in yet another crate
+            let other_crates_items = if def_id.crate == cdata.cnum {
+                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)) {
+                        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)