about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKang Seonghoon <public+git@mearie.org>2014-04-09 03:25:54 +0900
committerAlex Crichton <alex@alexcrichton.com>2014-04-10 15:21:59 -0700
commit85299e360cda49d61b8d9a509319e19bc206c336 (patch)
tree679aa3ed13ee05773e25137324533858baa0a3f4
parent34ece7ad718469b4634d5eadd91d078d95bbd6c5 (diff)
rustdoc: Prune the paths that do not appear in the index.
For the full library and compiler docs, the size of
`search-index.js` decreases by 13% (18.5% after gzip -9)
which is a substantial gain.
-rw-r--r--src/librustdoc/html/render.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 9e5c8f05c50..ff437ff23dc 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -262,10 +262,11 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
     cache.stack.push(krate.name.clone());
     krate = cache.fold_crate(krate);
     {
+        let Cache { search_index: ref mut index,
+                    orphan_methods: ref meths, paths: ref mut paths, ..} = cache;
+
         // Attach all orphan methods to the type's definition if the type
         // has since been learned.
-        let Cache { search_index: ref mut index,
-                    orphan_methods: ref meths, paths: ref paths, ..} = cache;
         for &(ref pid, ref item) in meths.iter() {
             match paths.find(pid) {
                 Some(&(ref fqp, _)) => {
@@ -280,6 +281,18 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
                 None => {}
             }
         };
+
+        // Prune the paths that do not appear in the index.
+        let mut unseen: HashSet<ast::NodeId> = paths.keys().map(|&id| id).collect();
+        for item in index.iter() {
+            match item.parent {
+                Some(ref pid) => { unseen.remove(pid); }
+                None => {}
+            }
+        }
+        for pid in unseen.iter() {
+            paths.remove(pid);
+        }
     }
 
     // Publish the search index