Skip to content

Commit 0571bc4

Browse files
committed
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).
1 parent 8fd946c commit 0571bc4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/librustdoc/html/static/main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1548,9 +1548,9 @@ function defocusSearchBar() {
15481548
} else if (type === "structfield" && parentType === "variant") {
15491549
// Structfields belonging to variants are special: the
15501550
// final path element is the enum name.
1551-
var splitPath = item.path.split("::");
1552-
var enumName = splitPath.pop();
1553-
path = splitPath.join("::");
1551+
var enumNameIdx = item.path.lastIndexOf("::");
1552+
var enumName = item.path.substr(enumNameIdx + 2);
1553+
path = item.path.substr(0, enumNameIdx);
15541554
displayPath = path + "::" + enumName + "::" + myparent.name + "::";
15551555
anchor = "#variant." + myparent.name + ".field." + name;
15561556
pageType = "enum";

0 commit comments

Comments
 (0)