Skip to content

Commit

Permalink
rustdoc: Prune the paths that do not appear in the index.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lifthrasiir authored and alexcrichton committed Apr 10, 2014
1 parent 34ece7a commit 85299e3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _)) => {
Expand All @@ -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
Expand Down

0 comments on commit 85299e3

Please sign in to comment.