Skip to content

Commit

Permalink
Rollup merge of #82809 - notriddle:microoptimize-main-js, r=Guillaume…
Browse files Browse the repository at this point in the history
…Gomez

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).
  • Loading branch information
GuillaumeGomez committed Mar 5, 2021
2 parents 1a08cb6 + 0571bc4 commit 8dfbc00
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 8dfbc00

Please sign in to comment.