about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-12 22:29:48 +0100
committerGitHub <noreply@github.com>2023-02-12 22:29:48 +0100
commit76c47fb90422e8ecef8af5f7f248978bfbf8963d (patch)
tree65837ea85ccce30b12c2272a3ccfcf19607a1812
parentca99d51b6d459500d43a1ffb52188c54041fc754 (diff)
parentd505c5abe4d2b03c0f714bc19087cb77f166a19a (diff)
downloadrust-76c47fb90422e8ecef8af5f7f248978bfbf8963d.tar.gz
rust-76c47fb90422e8ecef8af5f7f248978bfbf8963d.zip
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````
-rw-r--r--src/librustdoc/html/static/js/search.js10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 251e806c2d9..ea1875d8e27 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -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;
     }
 
     /**