rustdoc: Use smaller sequential numbers instead of NodeId
s for parents.
`allPaths` is now a flat array in effect. This decreases the size of the search index by about 4--5% (gzipped or not).
This commit is contained in:
parent
5d284a0daa
commit
ab6915d7b5
1 changed files with 22 additions and 13 deletions
|
@ -262,6 +262,9 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
});
|
});
|
||||||
cache.stack.push(krate.name.clone());
|
cache.stack.push(krate.name.clone());
|
||||||
krate = cache.fold_crate(krate);
|
krate = cache.fold_crate(krate);
|
||||||
|
|
||||||
|
let mut nodeid_to_pathid = HashMap::new();
|
||||||
|
let mut pathid_to_nodeid = Vec::new();
|
||||||
{
|
{
|
||||||
let Cache { search_index: ref mut index,
|
let Cache { search_index: ref mut index,
|
||||||
orphan_methods: ref meths, paths: ref mut paths, ..} = cache;
|
orphan_methods: ref meths, paths: ref mut paths, ..} = cache;
|
||||||
|
@ -283,17 +286,21 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prune the paths that do not appear in the index.
|
// Reduce `NodeId` in paths into smaller sequential numbers,
|
||||||
let mut unseen: HashSet<ast::NodeId> = paths.keys().map(|&id| id).collect();
|
// and prune the paths that do not appear in the index.
|
||||||
for item in index.iter() {
|
for item in index.iter() {
|
||||||
match item.parent {
|
match item.parent {
|
||||||
Some(ref pid) => { unseen.remove(pid); }
|
Some(nodeid) => {
|
||||||
|
if !nodeid_to_pathid.contains_key(&nodeid) {
|
||||||
|
let pathid = pathid_to_nodeid.len();
|
||||||
|
nodeid_to_pathid.insert(nodeid, pathid);
|
||||||
|
pathid_to_nodeid.push(nodeid);
|
||||||
|
}
|
||||||
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for pid in unseen.iter() {
|
assert_eq!(nodeid_to_pathid.len(), pathid_to_nodeid.len());
|
||||||
paths.remove(pid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish the search index
|
// Publish the search index
|
||||||
|
@ -308,23 +315,25 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
item.ty, item.name, item.path,
|
item.ty, item.name, item.path,
|
||||||
item.desc.to_json().to_str()));
|
item.desc.to_json().to_str()));
|
||||||
match item.parent {
|
match item.parent {
|
||||||
Some(id) => {
|
Some(nodeid) => {
|
||||||
try!(write!(&mut w, ",parent:'{}'", id));
|
let pathid = *nodeid_to_pathid.find(&nodeid).unwrap();
|
||||||
|
try!(write!(&mut w, ",parent:{}", pathid));
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "\\}"));
|
try!(write!(&mut w, "\\}"));
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "];"));
|
try!(write!(&mut w, "];"));
|
||||||
try!(write!(&mut w, "allPaths['{}'] = \\{", krate.name));
|
try!(write!(&mut w, "allPaths['{}'] = [", krate.name));
|
||||||
for (i, (&id, &(ref fqp, short))) in cache.paths.iter().enumerate() {
|
for (i, &nodeid) in pathid_to_nodeid.iter().enumerate() {
|
||||||
|
let &(ref fqp, short) = cache.paths.find(&nodeid).unwrap();
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
try!(write!(&mut w, ","));
|
try!(write!(&mut w, ","));
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "'{}':\\{type:'{}',name:'{}'\\}",
|
try!(write!(&mut w, "\\{type:'{}',name:'{}'\\}",
|
||||||
id, short, *fqp.last().unwrap()));
|
short, *fqp.last().unwrap()));
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "\\};"));
|
try!(write!(&mut w, "];"));
|
||||||
|
|
||||||
str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
|
str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue