1
Fork 0

rustdoc: Use an array instead of an object for the search index.

`buildIndex` JS function recovers them into the original object form.
This greatly reduces the size of the uncompressed search index (27%),
while this effect is less visible after gzipped (~5%).
This commit is contained in:
Kang Seonghoon 2014-04-09 17:16:09 +09:00
parent f1de04c760
commit f6854ab46c
2 changed files with 16 additions and 12 deletions

View file

@ -313,17 +313,17 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
if i > 0 {
try!(write!(&mut w, ","));
}
try!(write!(&mut w, "\\{ty:{:u},name:\"{}\",path:\"{}\",desc:{}",
try!(write!(&mut w, r#"[{:u},"{}","{}",{}"#,
item.ty, item.name, item.path,
item.desc.to_json().to_str()));
match item.parent {
Some(nodeid) => {
let pathid = *nodeid_to_pathid.find(&nodeid).unwrap();
try!(write!(&mut w, ",parent:{}", pathid));
try!(write!(&mut w, ",{}", pathid));
}
None => {}
}
try!(write!(&mut w, "\\}"));
try!(write!(&mut w, "]"));
}
try!(write!(&mut w, "];"));
try!(write!(&mut w, "allPaths['{}'] = [", krate.name));
@ -332,7 +332,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
if i > 0 {
try!(write!(&mut w, ","));
}
try!(write!(&mut w, "\\{type:{:u},name:'{}'\\}",
try!(write!(&mut w, r#"[{:u},"{}"]"#,
short, *fqp.last().unwrap()));
}
try!(write!(&mut w, "];"));

View file

@ -294,7 +294,7 @@
if ((validate) &&
(name.toLowerCase().indexOf(keys[i]) > -1 ||
path.toLowerCase().indexOf(keys[i]) > -1 ||
parent.name.toLowerCase().indexOf(keys[i]) > -1))
parent[1].toLowerCase().indexOf(keys[i]) > -1))
{
validate = true;
} else {
@ -423,12 +423,14 @@
'">' + name + '</a>';
} else if (item.parent !== undefined) {
var myparent = allPaths[item.crate][item.parent];
var parentType = myparent[0];
var parentName = myparent[1];
var anchor = '#' + type + '.' + name;
output += item.path + '::' + myparent.name +
output += item.path + '::' + parentName +
'::<a href="' + rootPath +
item.path.replace(/::/g, '/') +
'/' + itemTypes[myparent.type] +
'.' + myparent.name +
'/' + itemTypes[parentType] +
'.' + parentName +
'.html' + anchor +
'" class="' + type +
'">' + name + '</a>';
@ -545,10 +547,12 @@
// all other search operations have access to this cached data for
// faster analysis operations
for (i = 0; i < len; i += 1) {
rawSearchIndex[crate][i].crate = crate;
searchIndex.push(rawSearchIndex[crate][i]);
if (typeof rawSearchIndex[crate][i].name === "string") {
var word = rawSearchIndex[crate][i].name.toLowerCase();
var rawRow = rawSearchIndex[crate][i];
var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
path: rawRow[2], desc: rawRow[3], parent: rawRow[4]};
searchIndex.push(row);
if (typeof row.name === "string") {
var word = row.name.toLowerCase();
searchWords.push(word);
} else {
searchWords.push("");