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

View file

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