diff options
Diffstat (limited to 'src/librustdoc/html/static/js/search.js')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 2caf214ff73..10e01b4e262 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1465,6 +1465,11 @@ class DocSearch { */ this.searchIndexEmptyDesc = new Map(); /** + * @type {Map<String, RoaringBitmap>} + */ + this.searchIndexUnstable = new Map(); + + /** * @type {Uint32Array} */ this.functionTypeFingerprint = new Uint32Array(0); @@ -2052,9 +2057,10 @@ class DocSearch { }; const descShardList = [descShard]; - // Deprecated items and items with no description + // Deprecated and unstable items and items with no description this.searchIndexDeprecated.set(crate, new RoaringBitmap(crateCorpus.c)); this.searchIndexEmptyDesc.set(crate, new RoaringBitmap(crateCorpus.e)); + this.searchIndexUnstable.set(crate, new RoaringBitmap(crateCorpus.u)); let descIndex = 0; /** @@ -3326,6 +3332,25 @@ class DocSearch { return a - b; } + // sort unstable items later + // FIXME: there is some doubt if this is the most effecient way to implement this. + // alternative options include: + // * put is_unstable on each item when the index is built. + // increases memory usage but avoids a hashmap lookup. + // * put is_unstable on each item before sorting. + // better worst case performance but worse average case performance. + a = Number( + // @ts-expect-error + this.searchIndexUnstable.get(aaa.item.crate).contains(aaa.item.bitIndex), + ); + b = Number( + // @ts-expect-error + this.searchIndexUnstable.get(bbb.item.crate).contains(bbb.item.bitIndex), + ); + if (a !== b) { + return a - b; + } + // sort by crate (current crate comes first) a = Number(aaa.item.crate !== preferredCrate); b = Number(bbb.item.crate !== preferredCrate); @@ -3340,6 +3365,13 @@ class DocSearch { return a - b; } + // sort doc alias items later + a = Number(aaa.item.is_alias === true); + b = Number(bbb.item.is_alias === true); + if (a !== b) { + return a - b; + } + // sort by item name (lexicographically larger goes later) let aw = aaa.word; let bw = bbb.word; |
