]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Omit repeated paths in the search index.
authorKang Seonghoon <public+git@mearie.org>
Wed, 9 Apr 2014 17:24:00 +0000 (02:24 +0900)
committerKang Seonghoon <public+git@mearie.org>
Mon, 14 Apr 2014 01:00:50 +0000 (10:00 +0900)
Since the items roughly follow the lexical order, there are
many consecutive items with the same path value which can be
easily compressed.

For the library and compiler docs, this commit decreases
the index size by 26% and 6% before and after gzip, respectively.

src/librustdoc/html/render.rs
src/librustdoc/html/static/main.js

index d7739daad57e7bac77114ef9bcbfdb87809036e5..669a489a4fb6e6ce2d0a34802af121fd1297f966 100644 (file)
@@ -309,12 +309,23 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
     let index = {
         let mut w = MemWriter::new();
         try!(write!(&mut w, r#"searchIndex['{}'] = \{"items":["#, krate.name));
+
+        let mut lastpath = ~"";
         for (i, item) in cache.search_index.iter().enumerate() {
+            // Omit the path if it is same to that of the prior item.
+            let path;
+            if lastpath == item.path {
+                path = "";
+            } else {
+                lastpath = item.path.clone();
+                path = item.path.as_slice();
+            };
+
             if i > 0 {
                 try!(write!(&mut w, ","));
             }
             try!(write!(&mut w, r#"[{:u},"{}","{}",{}"#,
-                        item.ty, item.name, item.path,
+                        item.ty, item.name, path,
                         item.desc.to_json().to_str()));
             match item.parent {
                 Some(nodeid) => {
@@ -325,7 +336,9 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
             }
             try!(write!(&mut w, "]"));
         }
+
         try!(write!(&mut w, r#"],"paths":["#));
+
         for (i, &nodeid) in pathid_to_nodeid.iter().enumerate() {
             let &(ref fqp, short) = cache.paths.find(&nodeid).unwrap();
             if i > 0 {
@@ -334,6 +347,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
             try!(write!(&mut w, r#"[{:u},"{}"]"#,
                         short, *fqp.last().unwrap()));
         }
+
         try!(write!(&mut w, r"]\};"));
 
         str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
index 9ef25c50206f650ff72cf606bfcc5faa6c7690ea..4b79ae89eef6bc41a0ba566c7752e3cb5f560afd 100644 (file)
 
                 // an array of [(Number) item type,
                 //              (String) name,
-                //              (String) full path,
+                //              (String) full path or empty string for previous path,
                 //              (String) description,
                 //              (optional Number) the parent path index to `paths`]
                 var items = rawSearchIndex[crate].items;
                 // all other search operations have access to this cached data for
                 // faster analysis operations
                 var len = items.length;
+                var lastPath = "";
                 for (var i = 0; i < len; i += 1) {
                     var rawRow = items[i];
                     var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
-                               path: rawRow[2], desc: rawRow[3],
+                               path: rawRow[2] || lastPath, desc: rawRow[3],
                                parent: paths[rawRow[4]]};
                     searchIndex.push(row);
                     if (typeof row.name === "string") {
                     } else {
                         searchWords.push("");
                     }
+                    lastPath = row.path;
                 }
             }
             return searchWords;