diff options
| author | Peter Jaszkowiak <p.jaszkow@gmail.com> | 2023-02-03 00:08:57 -0700 |
|---|---|---|
| committer | Peter Jaszkowiak <p.jaszkow@gmail.com> | 2023-03-10 12:20:38 -0700 |
| commit | d2e4b59e60aae6f47baae337a3a7f9f04c728592 (patch) | |
| tree | 559ae76ecb07296d697e15500bc981476c38a700 /src/librustdoc/html/static | |
| parent | 6c991b07403a3234dd1ec0ac973b8ef97055e605 (diff) | |
| download | rust-d2e4b59e60aae6f47baae337a3a7f9f04c728592.tar.gz rust-d2e4b59e60aae6f47baae337a3a7f9f04c728592.zip | |
rustdoc: sort deprecated items lower in search
serialize `q` (`itemPaths`) sparsely overall 4% reduction in search index size
Diffstat (limited to 'src/librustdoc/html/static')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 88592fa0c84..5697d005b33 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -811,6 +811,13 @@ function initSearch(rawSearchIndex) { return a - b; } + // sort deprecated items later + a = aaa.item.deprecated; + b = bbb.item.deprecated; + if (a !== b) { + return a - b; + } + // sort by crate (current crate comes first) a = (aaa.item.crate !== preferredCrate); b = (bbb.item.crate !== preferredCrate); @@ -1170,6 +1177,7 @@ function initSearch(rawSearchIndex) { parent: item.parent, type: item.type, is_alias: true, + deprecated: item.deprecated, }; } @@ -1965,10 +1973,11 @@ function initSearch(rawSearchIndex) { * n: Array<string>, * t: Array<Number>, * d: Array<string>, - * q: Array<string>, + * q: Array<[Number, string]>, * i: Array<Number>, * f: Array<RawFunctionSearchType>, * p: Array<Object>, + * c: Array<Number> * }} */ const crateCorpus = rawSearchIndex[crate]; @@ -1987,6 +1996,7 @@ function initSearch(rawSearchIndex) { type: null, id: id, normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""), + deprecated: null, }; id += 1; searchIndex.push(crateRow); @@ -1996,14 +2006,20 @@ function initSearch(rawSearchIndex) { const itemTypes = crateCorpus.t; // an array of (String) item names const itemNames = crateCorpus.n; - // an array of (String) full paths (or empty string for previous path) - const itemPaths = crateCorpus.q; + // an array of [(Number) item index, + // (String) full path] + // an item whose index is not present will fall back to the previous present path + // i.e. if indices 4 and 11 are present, but 5-10 and 12-13 are not present, + // 5-10 will fall back to the path for 4 and 12-13 will fall back to the path for 11 + const itemPaths = new Map(crateCorpus.q); // an array of (String) descriptions const itemDescs = crateCorpus.d; // an array of (Number) the parent path index + 1 to `paths`, or 0 if none const itemParentIdxs = crateCorpus.i; // an array of (Object | null) the type of the function, if any const itemFunctionSearchTypes = crateCorpus.f; + // an array of (Number) indices for the deprecated items + const deprecatedItems = new Set(crateCorpus.c); // an array of [(Number) item type, // (String) name] const paths = crateCorpus.p; @@ -2045,12 +2061,13 @@ function initSearch(rawSearchIndex) { crate: crate, ty: itemTypes[i], name: itemNames[i], - path: itemPaths[i] ? itemPaths[i] : lastPath, + path: itemPaths.has(i) ? itemPaths.get(i) : lastPath, desc: itemDescs[i], parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, type: buildFunctionSearchType(itemFunctionSearchTypes[i], lowercasePaths), id: id, normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""), + deprecated: deprecatedItems.has(i), }; id += 1; searchIndex.push(row); |
