diff options
| author | Michael Howell <michael@notriddle.com> | 2024-01-06 14:07:12 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2024-03-11 21:22:03 -0700 |
| commit | 23e931fd076cc1d02a34b3f9bd9a64f92c8f4289 (patch) | |
| tree | 88769c46616cf1cbb0a9211dc54cd863a9b5372d | |
| parent | d38527eb82fd10ee5578b541b06904611f6f8427 (diff) | |
| download | rust-23e931fd076cc1d02a34b3f9bd9a64f92c8f4289.tar.gz rust-23e931fd076cc1d02a34b3f9bd9a64f92c8f4289.zip | |
rustdoc: use `const` for the special type name ids
Initialize them before the search index is loaded.
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index f8d1714e866..6c285ba6f51 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -245,49 +245,49 @@ function initSearch(rawSearchIndex) { * * @type {Map<string, {id: integer, assocOnly: boolean}>} */ - let typeNameIdMap; + const typeNameIdMap = new Map(); const ALIASES = new Map(); /** * Special type name IDs for searching by array. */ - let typeNameIdOfArray; + const typeNameIdOfArray = buildTypeMapIndex("array"); /** * Special type name IDs for searching by slice. */ - let typeNameIdOfSlice; + const typeNameIdOfSlice = buildTypeMapIndex("slice"); /** * Special type name IDs for searching by both array and slice (`[]` syntax). */ - let typeNameIdOfArrayOrSlice; + const typeNameIdOfArrayOrSlice = buildTypeMapIndex("[]"); /** * Special type name IDs for searching by tuple. */ - let typeNameIdOfTuple; + const typeNameIdOfTuple = buildTypeMapIndex("tuple"); /** * Special type name IDs for searching by unit. */ - let typeNameIdOfUnit; + const typeNameIdOfUnit = buildTypeMapIndex("unit"); /** * Special type name IDs for searching by both tuple and unit (`()` syntax). */ - let typeNameIdOfTupleOrUnit; + const typeNameIdOfTupleOrUnit = buildTypeMapIndex("()"); /** * Special type name IDs for searching `fn`. */ - let typeNameIdOfFn; + const typeNameIdOfFn = buildTypeMapIndex("fn"); /** * Special type name IDs for searching `fnmut`. */ - let typeNameIdOfFnMut; + const typeNameIdOfFnMut = buildTypeMapIndex("fnmut"); /** * Special type name IDs for searching `fnonce`. */ - let typeNameIdOfFnOnce; + const typeNameIdOfFnOnce = buildTypeMapIndex("fnonce"); /** * Special type name IDs for searching higher order functions (`->` syntax). */ - let typeNameIdOfHof; + const typeNameIdOfHof = buildTypeMapIndex("->"); /** * Add an item to the type Name->ID map, or, if one already exists, use it. @@ -3159,24 +3159,10 @@ ${item.displayPath}<span class="${type}">${name}</span>\ */ function buildIndex(rawSearchIndex) { searchIndex = []; - typeNameIdMap = new Map(); const charA = "A".charCodeAt(0); let currentIndex = 0; let id = 0; - // Initialize type map indexes for primitive list types - // that can be searched using `[]` syntax. - typeNameIdOfArray = buildTypeMapIndex("array"); - typeNameIdOfSlice = buildTypeMapIndex("slice"); - typeNameIdOfTuple = buildTypeMapIndex("tuple"); - typeNameIdOfUnit = buildTypeMapIndex("unit"); - typeNameIdOfArrayOrSlice = buildTypeMapIndex("[]"); - typeNameIdOfTupleOrUnit = buildTypeMapIndex("()"); - typeNameIdOfFn = buildTypeMapIndex("fn"); - typeNameIdOfFnMut = buildTypeMapIndex("fnmut"); - typeNameIdOfFnOnce = buildTypeMapIndex("fnonce"); - typeNameIdOfHof = buildTypeMapIndex("->"); - // Function type fingerprints are 128-bit bloom filters that are used to // estimate the distance between function and query. // This loop counts the number of items to allocate a fingerprint for. |
