Skip to content

Commit 23e931f

Browse files
committed
rustdoc: use const for the special type name ids
Initialize them before the search index is loaded.
1 parent d38527e commit 23e931f

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

src/librustdoc/html/static/js/search.js

+11-25
Original file line numberDiff line numberDiff line change
@@ -245,49 +245,49 @@ function initSearch(rawSearchIndex) {
245245
*
246246
* @type {Map<string, {id: integer, assocOnly: boolean}>}
247247
*/
248-
let typeNameIdMap;
248+
const typeNameIdMap = new Map();
249249
const ALIASES = new Map();
250250

251251
/**
252252
* Special type name IDs for searching by array.
253253
*/
254-
let typeNameIdOfArray;
254+
const typeNameIdOfArray = buildTypeMapIndex("array");
255255
/**
256256
* Special type name IDs for searching by slice.
257257
*/
258-
let typeNameIdOfSlice;
258+
const typeNameIdOfSlice = buildTypeMapIndex("slice");
259259
/**
260260
* Special type name IDs for searching by both array and slice (`[]` syntax).
261261
*/
262-
let typeNameIdOfArrayOrSlice;
262+
const typeNameIdOfArrayOrSlice = buildTypeMapIndex("[]");
263263
/**
264264
* Special type name IDs for searching by tuple.
265265
*/
266-
let typeNameIdOfTuple;
266+
const typeNameIdOfTuple = buildTypeMapIndex("tuple");
267267
/**
268268
* Special type name IDs for searching by unit.
269269
*/
270-
let typeNameIdOfUnit;
270+
const typeNameIdOfUnit = buildTypeMapIndex("unit");
271271
/**
272272
* Special type name IDs for searching by both tuple and unit (`()` syntax).
273273
*/
274-
let typeNameIdOfTupleOrUnit;
274+
const typeNameIdOfTupleOrUnit = buildTypeMapIndex("()");
275275
/**
276276
* Special type name IDs for searching `fn`.
277277
*/
278-
let typeNameIdOfFn;
278+
const typeNameIdOfFn = buildTypeMapIndex("fn");
279279
/**
280280
* Special type name IDs for searching `fnmut`.
281281
*/
282-
let typeNameIdOfFnMut;
282+
const typeNameIdOfFnMut = buildTypeMapIndex("fnmut");
283283
/**
284284
* Special type name IDs for searching `fnonce`.
285285
*/
286-
let typeNameIdOfFnOnce;
286+
const typeNameIdOfFnOnce = buildTypeMapIndex("fnonce");
287287
/**
288288
* Special type name IDs for searching higher order functions (`->` syntax).
289289
*/
290-
let typeNameIdOfHof;
290+
const typeNameIdOfHof = buildTypeMapIndex("->");
291291

292292
/**
293293
* 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>\
31593159
*/
31603160
function buildIndex(rawSearchIndex) {
31613161
searchIndex = [];
3162-
typeNameIdMap = new Map();
31633162
const charA = "A".charCodeAt(0);
31643163
let currentIndex = 0;
31653164
let id = 0;
31663165

3167-
// Initialize type map indexes for primitive list types
3168-
// that can be searched using `[]` syntax.
3169-
typeNameIdOfArray = buildTypeMapIndex("array");
3170-
typeNameIdOfSlice = buildTypeMapIndex("slice");
3171-
typeNameIdOfTuple = buildTypeMapIndex("tuple");
3172-
typeNameIdOfUnit = buildTypeMapIndex("unit");
3173-
typeNameIdOfArrayOrSlice = buildTypeMapIndex("[]");
3174-
typeNameIdOfTupleOrUnit = buildTypeMapIndex("()");
3175-
typeNameIdOfFn = buildTypeMapIndex("fn");
3176-
typeNameIdOfFnMut = buildTypeMapIndex("fnmut");
3177-
typeNameIdOfFnOnce = buildTypeMapIndex("fnonce");
3178-
typeNameIdOfHof = buildTypeMapIndex("->");
3179-
31803166
// Function type fingerprints are 128-bit bloom filters that are used to
31813167
// estimate the distance between function and query.
31823168
// This loop counts the number of items to allocate a fingerprint for.

0 commit comments

Comments
 (0)