about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-03-05 21:44:44 +0100
committerGitHub <noreply@github.com>2021-03-05 21:44:44 +0100
commit8dfbc00d277e4aa74f4e8d5639fac8e98c4f3ecf (patch)
tree15ef6ef45bce119924b89f462bae3ca7e6dc812f /src
parent1a08cb6a36b2c6cad8ffe68e1b819b01d6a1f9c7 (diff)
parent0571bc42637a9f07c4efe7669c48898d6cc8e25e (diff)
downloadrust-8dfbc00d277e4aa74f4e8d5639fac8e98c4f3ecf.tar.gz
rust-8dfbc00d277e4aa74f4e8d5639fac8e98c4f3ecf.zip
Rollup merge of #82809 - notriddle:microoptimize-main-js, r=GuillaumeGomez
rustdoc: Use substrings instead of split to grab enum variant paths

Both versions are about equally readable, but this version avoids scanning the entire path and building an intermediate array (`split()` in Rust is a lazy iterator, but not in JavaScript).
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/static/main.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index c9b8100fd03..d5071cec0c8 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -1548,9 +1548,9 @@ function defocusSearchBar() {
                 } else if (type === "structfield" && parentType === "variant") {
                     // Structfields belonging to variants are special: the
                     // final path element is the enum name.
-                    var splitPath = item.path.split("::");
-                    var enumName = splitPath.pop();
-                    path = splitPath.join("::");
+                    var enumNameIdx = item.path.lastIndexOf("::");
+                    var enumName = item.path.substr(enumNameIdx + 2);
+                    path = item.path.substr(0, enumNameIdx);
                     displayPath = path + "::" + enumName + "::" + myparent.name + "::";
                     anchor = "#variant." + myparent.name + ".field." + name;
                     pageType = "enum";