未验证 提交 8dfbc00d 编写于 作者: G Guillaume Gomez 提交者: GitHub

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).
...@@ -1548,9 +1548,9 @@ function defocusSearchBar() { ...@@ -1548,9 +1548,9 @@ function defocusSearchBar() {
} else if (type === "structfield" && parentType === "variant") { } else if (type === "structfield" && parentType === "variant") {
// Structfields belonging to variants are special: the // Structfields belonging to variants are special: the
// final path element is the enum name. // final path element is the enum name.
var splitPath = item.path.split("::"); var enumNameIdx = item.path.lastIndexOf("::");
var enumName = splitPath.pop(); var enumName = item.path.substr(enumNameIdx + 2);
path = splitPath.join("::"); path = item.path.substr(0, enumNameIdx);
displayPath = path + "::" + enumName + "::" + myparent.name + "::"; displayPath = path + "::" + enumName + "::" + myparent.name + "::";
anchor = "#variant." + myparent.name + ".field." + name; anchor = "#variant." + myparent.name + ".field." + name;
pageType = "enum"; pageType = "enum";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册