Skip to content

Commit d505c5a

Browse files
Improve JS function itemTypeFromName code a bit
1 parent 5919f62 commit d505c5a

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)