Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ccd95ac

Browse files
committed
search.js: improve typechecking by avoiding Map.has
1 parent c123adf commit ccd95ac

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,10 +1310,9 @@ class NameTrie {
13101310
let sste;
13111311
if (substart >= 2) {
13121312
const tail = name.substring(substart - 2, substart + 1);
1313-
if (tailTable.has(tail)) {
1314-
// it's not undefined
1315-
// @ts-expect-error
1316-
sste = tailTable.get(tail);
1313+
const entry = tailTable.get(tail);
1314+
if (entry !== undefined) {
1315+
sste = entry;
13171316
} else {
13181317
sste = [];
13191318
tailTable.set(tail, sste);
@@ -1337,10 +1336,9 @@ class NameTrie {
13371336
new Lev1TParametricDescription(name.length);
13381337
this.searchLev(name, 0, levParams, results);
13391338
const tail = name.substring(0, 3);
1340-
if (tailTable.has(tail)) {
1341-
// it's not undefined
1342-
// @ts-expect-error
1343-
for (const entry of tailTable.get(tail)) {
1339+
const list = tailTable.get(tail);
1340+
if (list !== undefined) {
1341+
for (const entry of list) {
13441342
entry.searchSubstringPrefix(name, 3, results);
13451343
}
13461344
}
@@ -1599,10 +1597,8 @@ class DocSearch {
15991597
return null;
16001598
}
16011599

1602-
if (this.typeNameIdMap.has(name)) {
1603-
/** @type {{id: number, assocOnly: boolean}} */
1604-
// @ts-expect-error
1605-
const obj = this.typeNameIdMap.get(name);
1600+
const obj = this.typeNameIdMap.get(name);
1601+
if (obj !== undefined) {
16061602
obj.assocOnly = !!(isAssocType && obj.assocOnly);
16071603
return obj.id;
16081604
} else {
@@ -2145,7 +2141,6 @@ class DocSearch {
21452141
const name = elem[1];
21462142
let path = null;
21472143
if (elem.length > 2 && elem[2] !== null) {
2148-
// @ts-expect-error
21492144
path = itemPaths.has(elem[2]) ? itemPaths.get(elem[2]) : lastPath;
21502145
lastPath = path;
21512146
}

0 commit comments

Comments
 (0)