]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Get rid of `allPaths` global variable by merging it into `searchIndex`.
authorKang Seonghoon <public+git@mearie.org>
Wed, 9 Apr 2014 16:27:35 +0000 (01:27 +0900)
committerKang Seonghoon <public+git@mearie.org>
Mon, 14 Apr 2014 01:00:49 +0000 (10:00 +0900)
src/librustdoc/html/render.rs
src/librustdoc/html/static/main.js

index aa54642262b83ab261063615451f68e3c6dcc6c4..d7739daad57e7bac77114ef9bcbfdb87809036e5 100644 (file)
@@ -308,7 +308,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
     // Publish the search index
     let index = {
         let mut w = MemWriter::new();
-        try!(write!(&mut w, "searchIndex['{}'] = [", krate.name));
+        try!(write!(&mut w, r#"searchIndex['{}'] = \{"items":["#, krate.name));
         for (i, item) in cache.search_index.iter().enumerate() {
             if i > 0 {
                 try!(write!(&mut w, ","));
@@ -325,8 +325,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
             }
             try!(write!(&mut w, "]"));
         }
-        try!(write!(&mut w, "];"));
-        try!(write!(&mut w, "allPaths['{}'] = [", krate.name));
+        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 {
@@ -335,7 +334,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, "];"));
+        try!(write!(&mut w, r"]\};"));
 
         str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
     };
@@ -371,7 +370,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
             }
         }
         let mut w = try!(File::create(&dst));
-        try!(writeln!(&mut w, r"var searchIndex = \{\}; var allPaths = \{\};"));
+        try!(writeln!(&mut w, r"var searchIndex = \{\};"));
         for index in all_indexes.iter() {
             try!(writeln!(&mut w, "{}", *index));
         }
index 692ab5b9ac2865df499f8a907a8a697a3d486bb8..9ef25c50206f650ff72cf606bfcc5faa6c7690ea 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 /*jslint browser: true, es5: true */
-/*globals $: true, rootPath: true, allPaths: true */
+/*globals $: true, rootPath: true */
 
 (function() {
     "use strict";
                 var result = results[i],
                     name = result.item.name.toLowerCase(),
                     path = result.item.path.toLowerCase(),
-                    parent = allPaths[result.item.crate][result.item.parent];
+                    parent = result.item.parent;
 
                 var valid = validateResult(name, path, split, parent);
                 if (!valid) {
                     if ((validate) &&
                         (name.toLowerCase().indexOf(keys[i]) > -1 ||
                          path.toLowerCase().indexOf(keys[i]) > -1 ||
-                         parent[1].toLowerCase().indexOf(keys[i]) > -1))
+                         parent.name.toLowerCase().indexOf(keys[i]) > -1))
                     {
                         validate = true;
                     } else {
                             '/index.html" class="' + type +
                             '">' + name + '</a>';
                     } else if (item.parent !== undefined) {
-                        var myparent = allPaths[item.crate][item.parent];
-                        var parentType = myparent[0];
-                        var parentName = myparent[1];
+                        var myparent = item.parent;
                         var anchor = '#' + type + '.' + name;
-                        output += item.path + '::' + parentName +
+                        output += item.path + '::' + myparent.name +
                             '::<a href="' + rootPath +
                             item.path.replace(/::/g, '/') +
-                            '/' + itemTypes[parentType] +
-                            '.' + parentName +
+                            '/' + itemTypes[myparent.ty] +
+                            '.' + myparent.name +
                             '.html' + anchor +
                             '" class="' + type +
                             '">' + name + '</a>';
             var searchWords = [];
             for (var crate in rawSearchIndex) {
                 if (!rawSearchIndex.hasOwnProperty(crate)) { continue }
-                var len = rawSearchIndex[crate].length;
-                var i = 0;
 
+                // an array of [(Number) item type,
+                //              (String) name,
+                //              (String) full path,
+                //              (String) description,
+                //              (optional Number) the parent path index to `paths`]
+                var items = rawSearchIndex[crate].items;
+                // an array of [(Number) item type,
+                //              (String) name]
+                var paths = rawSearchIndex[crate].paths;
+
+                // convert `paths` into an object form
+                var len = paths.length;
+                for (var i = 0; i < len; ++i) {
+                    paths[i] = {ty: paths[i][0], name: paths[i][1]};
+                }
+
+                // convert `items` into an object form, and construct word indices.
+                //
                 // before any analysis is performed lets gather the search terms to
                 // search against apart from the rest of the data.  This is a quick
                 // operation that is cached for the life of the page state so that
                 // all other search operations have access to this cached data for
                 // faster analysis operations
-                for (i = 0; i < len; i += 1) {
-                    var rawRow = rawSearchIndex[crate][i];
+                var len = items.length;
+                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], parent: rawRow[4]};
+                               path: rawRow[2], desc: rawRow[3],
+                               parent: paths[rawRow[4]]};
                     searchIndex.push(row);
                     if (typeof row.name === "string") {
                         var word = row.name.toLowerCase();