Skip to content

Commit 76c47fb

Browse files
authored
Rollup merge of #107930 - GuillaumeGomez:js-func-improvement, r=notriddle
Improve JS function itemTypeFromName code a bit Very small code improvement replacing a `for` loop with `findIndex` method. r? ````@notriddle````
2 parents ca99d51 + d505c5a commit 76c47fb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,11 @@ function initSearch(rawSearchIndex) {
142142
}
143143

144144
function itemTypeFromName(typename) {
145-
for (let i = 0, len = itemTypes.length; i < len; ++i) {
146-
if (itemTypes[i] === typename) {
147-
return i;
148-
}
145+
const index = itemTypes.findIndex(i => i === typename);
146+
if (index < 0) {
147+
throw new Error("Unknown type filter `" + typename + "`");
149148
}
150-
151-
throw new Error("Unknown type filter `" + typename + "`");
149+
return index;
152150
}
153151

154152
/**

0 commit comments

Comments
 (0)