Skip to content

Commit

Permalink
Use substrings instead of split to grab enum variant paths
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
notriddle committed Mar 5, 2021
1 parent 8fd946c commit 0571bc4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 0571bc4

Please sign in to comment.