diff options
| author | Kang Seonghoon <public+git@mearie.org> | 2014-04-10 01:27:35 +0900 |
|---|---|---|
| committer | Kang Seonghoon <public+git@mearie.org> | 2014-04-14 10:00:49 +0900 |
| commit | 9eb336a0206178f52146d41dd152166233df703b (patch) | |
| tree | 0a9d3f97b43886a8ed6e205043638b7d2cbc2f2a /src/librustdoc/html/static | |
| parent | f6854ab46c1303cfee508a4537e235166cd6cc3e (diff) | |
| download | rust-9eb336a0206178f52146d41dd152166233df703b.tar.gz rust-9eb336a0206178f52146d41dd152166233df703b.zip | |
rustdoc: Get rid of `allPaths` global variable by merging it into `searchIndex`.
Diffstat (limited to 'src/librustdoc/html/static')
| -rw-r--r-- | src/librustdoc/html/static/main.js | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 692ab5b9ac2..9ef25c50206 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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"; @@ -258,7 +258,7 @@ 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) { @@ -294,7 +294,7 @@ 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 { @@ -422,15 +422,13 @@ '/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>'; @@ -538,18 +536,36 @@ 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(); |
