Skip to content

Commit

Permalink
Rollup merge of #107930 - GuillaumeGomez:js-func-improvement, r=notri…
Browse files Browse the repository at this point in the history
…ddle

Improve JS function itemTypeFromName code a bit

Very small code improvement replacing a `for` loop with `findIndex` method.

r? ````@notriddle````
  • Loading branch information
matthiaskrgr authored Feb 12, 2023
2 parents ca99d51 + d505c5a commit 76c47fb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,11 @@ function initSearch(rawSearchIndex) {
}

function itemTypeFromName(typename) {
for (let i = 0, len = itemTypes.length; i < len; ++i) {
if (itemTypes[i] === typename) {
return i;
}
const index = itemTypes.findIndex(i => i === typename);
if (index < 0) {
throw new Error("Unknown type filter `" + typename + "`");
}

throw new Error("Unknown type filter `" + typename + "`");
return index;
}

/**
Expand Down

0 comments on commit 76c47fb

Please sign in to comment.