1
Fork 0

Prevent lazy iterations over DOM

This commit is contained in:
Guillaume Gomez 2018-11-26 17:17:38 +01:00
parent edfe2a893e
commit 34e31830c0

View file

@ -148,12 +148,10 @@ if (!DOMTokenList.prototype.remove) {
var TY_PRIMITIVE = itemTypes.indexOf("primitive"); var TY_PRIMITIVE = itemTypes.indexOf("primitive");
var TY_KEYWORD = itemTypes.indexOf("keyword"); var TY_KEYWORD = itemTypes.indexOf("keyword");
onEach(document.getElementsByClassName("js-only"), function(e) { onEach(Array.prototype.slice.call(document.getElementsByClassName("js-only")), function(e) {
removeClass(e, "js-only"); removeClass(e, "js-only");
}); });
console.log('1', Date.now() - start);
function getQueryStringParams() { function getQueryStringParams() {
var params = {}; var params = {};
window.location.search.substring(1).split("&"). window.location.search.substring(1).split("&").
@ -170,6 +168,8 @@ if (!DOMTokenList.prototype.remove) {
window.history && typeof window.history.pushState === "function"; window.history && typeof window.history.pushState === "function";
} }
var main = document.getElementById("main");
function highlightSourceLines(ev) { function highlightSourceLines(ev) {
// If we're in mobile mode, we should add the sidebar in any case. // If we're in mobile mode, we should add the sidebar in any case.
hideSidebar(); hideSidebar();
@ -190,8 +190,9 @@ if (!DOMTokenList.prototype.remove) {
x.scrollIntoView(); x.scrollIntoView();
} }
} }
onEach(document.getElementsByClassName("line-numbers"), function(e) { onEach(Array.prototype.slice.call(document.getElementsByClassName("line-numbers")),
onEach(e.getElementsByTagName("span"), function(i_e) { function(e) {
onEach(Array.prototype.slice.call(e.getElementsByTagName("span")), function(i_e) {
removeClass(i_e, "line-highlighted"); removeClass(i_e, "line-highlighted");
}); });
}); });
@ -200,7 +201,7 @@ if (!DOMTokenList.prototype.remove) {
} }
} else if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) { } else if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
addClass(search, "hidden"); addClass(search, "hidden");
removeClass(document.getElementById("main"), "hidden"); removeClass(main, "hidden");
var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1); var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
history.replaceState(hash, "", "?search=#" + hash); history.replaceState(hash, "", "?search=#" + hash);
@ -233,8 +234,6 @@ if (!DOMTokenList.prototype.remove) {
highlightSourceLines(null); highlightSourceLines(null);
window.onhashchange = highlightSourceLines; window.onhashchange = highlightSourceLines;
console.log('2', Date.now() - start);
// Gets the human-readable string for the virtual-key code of the // Gets the human-readable string for the virtual-key code of the
// given KeyboardEvent, ev. // given KeyboardEvent, ev.
// //
@ -279,7 +278,7 @@ if (!DOMTokenList.prototype.remove) {
} else if (hasClass(search, "hidden") === false) { } else if (hasClass(search, "hidden") === false) {
ev.preventDefault(); ev.preventDefault();
addClass(search, "hidden"); addClass(search, "hidden");
removeClass(document.getElementById("main"), "hidden"); removeClass(main, "hidden");
document.title = titleBeforeSearch; document.title = titleBeforeSearch;
} }
defocusSearchBar(); defocusSearchBar();
@ -407,8 +406,6 @@ if (!DOMTokenList.prototype.remove) {
}; };
} }
console.log('3', Date.now() - start);
/** /**
* A function to compute the Levenshtein distance between two strings * A function to compute the Levenshtein distance between two strings
* Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported * Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
@ -1183,7 +1180,7 @@ if (!DOMTokenList.prototype.remove) {
dst = dst[0]; dst = dst[0];
if (window.location.pathname === dst.pathname) { if (window.location.pathname === dst.pathname) {
addClass(document.getElementById("search"), "hidden"); addClass(document.getElementById("search"), "hidden");
removeClass(document.getElementById("main"), "hidden"); removeClass(main, "hidden");
document.location.href = dst.href; document.location.href = dst.href;
} }
}; };
@ -1411,7 +1408,7 @@ if (!DOMTokenList.prototype.remove) {
"</div><div id=\"results\">" + "</div><div id=\"results\">" +
ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>"; ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";
addClass(document.getElementById("main"), "hidden"); addClass(main, "hidden");
var search = document.getElementById("search"); var search = document.getElementById("search");
removeClass(search, "hidden"); removeClass(search, "hidden");
search.innerHTML = output; search.innerHTML = output;
@ -1421,7 +1418,7 @@ if (!DOMTokenList.prototype.remove) {
td_width = tds[0].offsetWidth; td_width = tds[0].offsetWidth;
} }
var width = search.offsetWidth - 40 - td_width; var width = search.offsetWidth - 40 - td_width;
onEach(search.getElementsByClassName("desc"), function(e) { onEach(Array.prototype.slice.call(search.getElementsByClassName("desc")), function(e) {
e.style.width = width + "px"; e.style.width = width + "px";
}); });
initSearchNav(); initSearchNav();
@ -1619,7 +1616,6 @@ if (!DOMTokenList.prototype.remove) {
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
history.replaceState("", "std - Rust", "?search="); history.replaceState("", "std - Rust", "?search=");
} }
var main = document.getElementById("main");
if (hasClass(main, "content")) { if (hasClass(main, "content")) {
removeClass(main, "hidden"); removeClass(main, "hidden");
} }
@ -1666,7 +1662,6 @@ if (!DOMTokenList.prototype.remove) {
// When browsing back from search results the main page // When browsing back from search results the main page
// visibility must be reset. // visibility must be reset.
if (!params.search) { if (!params.search) {
var main = document.getElementById("main");
if (hasClass(main, "content")) { if (hasClass(main, "content")) {
removeClass(main, "hidden"); removeClass(main, "hidden");
} }
@ -1862,8 +1857,6 @@ if (!DOMTokenList.prototype.remove) {
window.register_implementors(window.pending_implementors); window.register_implementors(window.pending_implementors);
} }
console.log('4', Date.now() - start);
function labelForToggleButton(sectionIsCollapsed) { function labelForToggleButton(sectionIsCollapsed) {
if (sectionIsCollapsed) { if (sectionIsCollapsed) {
// button will expand the section // button will expand the section
@ -1889,31 +1882,35 @@ if (!DOMTokenList.prototype.remove) {
} }
function toggleAllDocs(pageId, fromAutoCollapse) { function toggleAllDocs(pageId, fromAutoCollapse) {
var toggle = document.getElementById("toggle-all-docs"); var innerToggle = document.getElementById("toggle-all-docs");
if (!toggle) { if (!innerToggle) {
return; return;
} }
if (hasClass(toggle, "will-expand")) { if (hasClass(innerToggle, "will-expand")) {
updateLocalStorage("rustdoc-collapse", "false"); updateLocalStorage("rustdoc-collapse", "false");
removeClass(toggle, "will-expand"); removeClass(innerToggle, "will-expand");
onEveryMatchingChild(toggle, "inner", function(e) { onEveryMatchingChild(innerToggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(false); e.innerHTML = labelForToggleButton(false);
}); });
toggle.title = "collapse all docs"; innerToggle.title = "collapse all docs";
if (fromAutoCollapse !== true) { if (fromAutoCollapse !== true) {
onEach(document.getElementsByClassName("collapse-toggle"), function(e) { onEach(Array.prototype.slice.call(
document.getElementsByClassName("collapse-toggle")),
function(e) {
collapseDocs(e, "show"); collapseDocs(e, "show");
}); });
} }
} else { } else {
updateLocalStorage("rustdoc-collapse", "true"); updateLocalStorage("rustdoc-collapse", "true");
addClass(toggle, "will-expand"); addClass(innerToggle, "will-expand");
onEveryMatchingChild(toggle, "inner", function(e) { onEveryMatchingChild(innerToggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(true); e.innerHTML = labelForToggleButton(true);
}); });
toggle.title = "expand all docs"; innerToggle.title = "expand all docs";
if (fromAutoCollapse !== true) { if (fromAutoCollapse !== true) {
onEach(document.getElementsByClassName("collapse-toggle"), function(e) { onEach(Array.prototype.slice.call(
document.getElementsByClassName("collapse-toggle")),
function(e) {
collapseDocs(e, "hide", pageId); collapseDocs(e, "hide", pageId);
}); });
} }
@ -1987,12 +1984,12 @@ if (!DOMTokenList.prototype.remove) {
} }
if (action === "hide") { if (action === "hide") {
addClass(relatedDoc, "hidden-by-usual-hider"); addClass(relatedDoc, "hidden-by-usual-hider");
onEach(toggle.childNodes, adjustToggle(true)); onEach(Array.prototype.slice.call(toggle.childNodes), adjustToggle(true));
addClass(toggle.parentNode, "collapsed"); addClass(toggle.parentNode, "collapsed");
} else if (action === "show") { } else if (action === "show") {
removeClass(relatedDoc, "hidden-by-usual-hider"); removeClass(relatedDoc, "hidden-by-usual-hider");
removeClass(toggle.parentNode, "collapsed"); removeClass(toggle.parentNode, "collapsed");
onEach(toggle.childNodes, adjustToggle(false)); onEach(Array.prototype.slice.call(toggle.childNodes), adjustToggle(false));
} }
} }
} else { } else {
@ -2025,13 +2022,13 @@ if (!DOMTokenList.prototype.remove) {
if (action === "show") { if (action === "show") {
removeClass(relatedDoc, "fns-now-collapsed"); removeClass(relatedDoc, "fns-now-collapsed");
removeClass(docblock, "hidden-by-usual-hider"); removeClass(docblock, "hidden-by-usual-hider");
onEach(toggle.childNodes, adjustToggle(false)); onEach(Array.prototype.slice.call(toggle.childNodes), adjustToggle(false));
onEach(relatedDoc.childNodes, implHider(false)); onEach(Array.prototype.slice.call(relatedDoc.childNodes), implHider(false));
} else if (action === "hide") { } else if (action === "hide") {
addClass(relatedDoc, "fns-now-collapsed"); addClass(relatedDoc, "fns-now-collapsed");
addClass(docblock, "hidden-by-usual-hider"); addClass(docblock, "hidden-by-usual-hider");
onEach(toggle.childNodes, adjustToggle(true)); onEach(Array.prototype.slice.call(toggle.childNodes), adjustToggle(true));
onEach(relatedDoc.childNodes, implHider(true)); onEach(Array.prototype.slice.call(relatedDoc.childNodes), implHider(true));
} }
} }
} }
@ -2055,7 +2052,9 @@ if (!DOMTokenList.prototype.remove) {
var impl_list = document.getElementById("implementations-list"); var impl_list = document.getElementById("implementations-list");
if (impl_list !== null) { if (impl_list !== null) {
onEach(impl_list.getElementsByClassName("collapse-toggle"), collapser); onEach(Array.prototype.slice.call(
impl_list.getElementsByClassName("collapse-toggle")),
collapser);
} }
} }
} }
@ -2069,30 +2068,30 @@ if (!DOMTokenList.prototype.remove) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
} }
function createSimpleToggle(sectionIsCollapsed) {
var toggle = document.createElement("a"); var toggle = document.createElement("a");
toggle.href = "javascript:void(0)"; toggle.href = "javascript:void(0)";
toggle.className = "collapse-toggle"; toggle.className = "collapse-toggle";
toggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(false) + "</span>]"; toggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(sectionIsCollapsed) +
"</span>]";
return toggle;
}
var toggle = createSimpleToggle(false);
var func = function(e) { var func = function(e) {
var next = e.nextElementSibling; var next = e.nextElementSibling;
if (next && hasClass(e, "impl") && hasClass(next, "docblock")) {
next = next.nextElementSibling;
}
if (!next) { if (!next) {
return; return;
} }
if ((hasClass(e, "method") || hasClass(e, "associatedconstant") || if (hasClass(next, "docblock") ||
next.getElementsByClassName("method").length > 0) &&
(hasClass(next, "docblock") ||
hasClass(e, "impl") ||
(hasClass(next, "stability") && (hasClass(next, "stability") &&
hasClass(next.nextElementSibling, "docblock")))) { hasClass(next.nextElementSibling, "docblock"))) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]); insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
} }
}; };
var func2 = function(e) { var funcImpl = function(e) {
var next = e.nextElementSibling; var next = e.nextElementSibling;
if (next && hasClass(next, "docblock")) { if (next && hasClass(next, "docblock")) {
next = next.nextElementSibling; next = next.nextElementSibling;
@ -2105,13 +2104,9 @@ if (!DOMTokenList.prototype.remove) {
} }
}; };
console.log('5', Date.now() - start); onEach(Array.prototype.slice.call(document.getElementsByClassName("method")), func);
onEach(document.getElementsByClassName("method"), func); onEach(Array.prototype.slice.call(document.getElementsByClassName("associatedconstant")), func);
console.log('6', Date.now() - start); onEach(Array.prototype.slice.call(document.getElementsByClassName("impl")), funcImpl);
onEach(document.getElementsByClassName("associatedconstant"), func);
console.log('7', Date.now() - start);
onEach(document.getElementsByClassName("impl"), func2 );
console.log('8', Date.now() - start);
var impl_call = function() {}; var impl_call = function() {};
if (getCurrentValue("rustdoc-method-docs") !== "false") { if (getCurrentValue("rustdoc-method-docs") !== "false") {
impl_call = function(e, newToggle, pageId) { impl_call = function(e, newToggle, pageId) {
@ -2132,7 +2127,8 @@ if (!DOMTokenList.prototype.remove) {
function toggleClicked() { function toggleClicked() {
if (hasClass(this, "collapsed")) { if (hasClass(this, "collapsed")) {
removeClass(this, "collapsed"); removeClass(this, "collapsed");
onEach(this.parentNode.getElementsByClassName("hidden"), function(x) { onEach(Array.prototype.slice.call(this.parentNode.getElementsByClassName("hidden")),
function(x) {
if (hasClass(x, "content") === false) { if (hasClass(x, "content") === false) {
removeClass(x, "hidden"); removeClass(x, "hidden");
addClass(x, "x"); addClass(x, "x");
@ -2142,7 +2138,8 @@ if (!DOMTokenList.prototype.remove) {
"</span>] Hide undocumented items"; "</span>] Hide undocumented items";
} else { } else {
addClass(this, "collapsed"); addClass(this, "collapsed");
onEach(this.parentNode.getElementsByClassName("x"), function(x) { onEach(Array.prototype.slice.call(this.parentNode.getElementsByClassName("x")),
function(x) {
if (hasClass(x, "content") === false) { if (hasClass(x, "content") === false) {
addClass(x, "hidden"); addClass(x, "hidden");
removeClass(x, "x"); removeClass(x, "x");
@ -2152,8 +2149,8 @@ if (!DOMTokenList.prototype.remove) {
"</span>] Show hidden undocumented items"; "</span>] Show hidden undocumented items";
} }
} }
onEach(document.getElementsByClassName("impl-items"), function(e) { onEach(Array.prototype.slice.call(document.getElementsByClassName("impl-items")), function(e) {
onEach(e.getElementsByClassName("associatedconstant"), func); onEach(Array.prototype.slice.call(e.getElementsByClassName("associatedconstant")), func);
var hiddenElems = e.getElementsByClassName("hidden"); var hiddenElems = e.getElementsByClassName("hidden");
var needToggle = false; var needToggle = false;
@ -2166,13 +2163,12 @@ if (!DOMTokenList.prototype.remove) {
} }
} }
if (needToggle === true) { if (needToggle === true) {
var toggle = newToggle.cloneNode(true); var inner_toggle = newToggle.cloneNode(true);
toggle.onclick = toggleClicked; inner_toggle.onclick = toggleClicked;
e.insertBefore(toggle, e.firstChild); e.insertBefore(inner_toggle, e.firstChild);
impl_call(e, toggle, pageId); impl_call(e, inner_toggle, pageId);
} }
}); });
console.log('9', Date.now() - start);
function createToggle(otherMessage, fontSize, extraClass, show) { function createToggle(otherMessage, fontSize, extraClass, show) {
var span = document.createElement("span"); var span = document.createElement("span");
@ -2214,15 +2210,18 @@ if (!DOMTokenList.prototype.remove) {
if (hasClass(e, "autohide")) { if (hasClass(e, "autohide")) {
var wrap = e.previousElementSibling; var wrap = e.previousElementSibling;
if (wrap && hasClass(wrap, "toggle-wrapper")) { if (wrap && hasClass(wrap, "toggle-wrapper")) {
var toggle = wrap.childNodes[0]; var inner_toggle = wrap.childNodes[0];
var extra = e.childNodes[0].tagName === "H3"; var extra = e.childNodes[0].tagName === "H3";
e.style.display = "none"; e.style.display = "none";
addClass(wrap, "collapsed"); addClass(wrap, "collapsed");
onEach(toggle.getElementsByClassName("inner"), function(e) { onEach(Array.prototype.slice.call(inner_toggle.getElementsByClassName("inner")),
function(e) {
e.innerHTML = labelForToggleButton(true); e.innerHTML = labelForToggleButton(true);
}); });
onEach(toggle.getElementsByClassName("toggle-label"), function(e) { onEach(Array.prototype.slice.call(
inner_toggle.getElementsByClassName("toggle-label")),
function(e) {
e.style.display = "inline-block"; e.style.display = "inline-block";
if (extra === true) { if (extra === true) {
i_e.innerHTML = " Show " + e.childNodes[0].innerHTML; i_e.innerHTML = " Show " + e.childNodes[0].innerHTML;
@ -2269,11 +2268,36 @@ if (!DOMTokenList.prototype.remove) {
} }
} }
console.log('10', Date.now() - start); onEach(Array.prototype.slice.call(document.getElementsByClassName("docblock")),
onEach(document.getElementsByClassName("docblock"), buildToggleWrapper); buildToggleWrapper);
console.log('11', Date.now() - start); onEach(Array.prototype.slice.call(document.getElementsByClassName("sub-variant")),
onEach(document.getElementsByClassName("sub-variant"), buildToggleWrapper); buildToggleWrapper);
console.log('12', Date.now() - start);
// In the search display, allows to switch between tabs.
function printTab(nb) {
if (nb === 0 || nb === 1 || nb === 2) {
currentTab = nb;
}
var nb_copy = nb;
onEach(Array.prototype.slice.call(document.getElementById("titles").childNodes),
function(elem) {
if (nb_copy === 0) {
addClass(elem, "selected");
} else {
removeClass(elem, "selected");
}
nb_copy -= 1;
});
onEach(Array.prototype.slice.call(document.getElementById("results").childNodes),
function(elem) {
if (nb === 0) {
elem.style.display = "";
} else {
elem.style.display = "none";
}
nb -= 1;
});
}
function createToggleWrapper(tog) { function createToggleWrapper(tog) {
var span = document.createElement("span"); var span = document.createElement("span");
@ -2288,30 +2312,6 @@ if (!DOMTokenList.prototype.remove) {
return wrapper; return wrapper;
} }
// In the search display, allows to switch between tabs.
function printTab(nb) {
if (nb === 0 || nb === 1 || nb === 2) {
currentTab = nb;
}
var nb_copy = nb;
onEach(document.getElementById("titles").childNodes, function(elem) {
if (nb_copy === 0) {
addClass(elem, "selected");
} else {
removeClass(elem, "selected");
}
nb_copy -= 1;
});
onEach(document.getElementById("results").childNodes, function(elem) {
if (nb === 0) {
elem.style.display = "";
} else {
elem.style.display = "none";
}
nb -= 1;
});
}
// To avoid checking on "rustdoc-item-attributes" value on every loop... // To avoid checking on "rustdoc-item-attributes" value on every loop...
var itemAttributesFunc = function() {}; var itemAttributesFunc = function() {};
if (getCurrentValue("rustdoc-item-attributes") !== "false") { if (getCurrentValue("rustdoc-item-attributes") !== "false") {
@ -2319,11 +2319,11 @@ if (!DOMTokenList.prototype.remove) {
collapseDocs(x.previousSibling.childNodes[0], "toggle"); collapseDocs(x.previousSibling.childNodes[0], "toggle");
}; };
} }
onEach(document.getElementById("main").getElementsByClassName("attributes"), function(i_e) { var attributesToggle = createToggleWrapper(createSimpleToggle(false));
i_e.parentNode.insertBefore(createToggleWrapper(toggle.cloneNode(true)), i_e); onEach(Array.prototype.slice.call(main.getElementsByClassName("attributes")), function(i_e) {
i_e.parentNode.insertBefore(attributesToggle.cloneNode(true), i_e);
itemAttributesFunc(i_e); itemAttributesFunc(i_e);
}); });
console.log('12a', Date.now() - start);
// To avoid checking on "rustdoc-line-numbers" value on every loop... // To avoid checking on "rustdoc-line-numbers" value on every loop...
var lineNumbersFunc = function() {}; var lineNumbersFunc = function() {};
@ -2340,8 +2340,8 @@ if (!DOMTokenList.prototype.remove) {
x.parentNode.insertBefore(node, x); x.parentNode.insertBefore(node, x);
}; };
} }
console.log('13', Date.now() - start); onEach(Array.prototype.slice.call(document.getElementsByClassName("rust-example-rendered")),
onEach(document.getElementsByClassName("rust-example-rendered"), function(e) { function(e) {
if (hasClass(e, "compile_fail")) { if (hasClass(e, "compile_fail")) {
e.addEventListener("mouseover", function(event) { e.addEventListener("mouseover", function(event) {
this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00"; this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
@ -2359,7 +2359,6 @@ if (!DOMTokenList.prototype.remove) {
} }
lineNumbersFunc(e); lineNumbersFunc(e);
}); });
console.log('14', Date.now() - start);
function showModal(content) { function showModal(content) {
var modal = document.createElement("div"); var modal = document.createElement("div");
@ -2380,16 +2379,16 @@ if (!DOMTokenList.prototype.remove) {
} }
} }
onEach(document.getElementsByClassName("important-traits"), function(e) { onEach(Array.prototype.slice.call(document.getElementsByClassName("important-traits")),
function(e) {
e.onclick = function() { e.onclick = function() {
showModal(e.lastElementChild.innerHTML); showModal(e.lastElementChild.innerHTML);
}; };
}); });
console.log('15', Date.now() - start);
function putBackSearch(search_input) { function putBackSearch(search_input) {
if (search_input.value !== "") { if (search_input.value !== "") {
addClass(document.getElementById("main"), "hidden"); addClass(main, "hidden");
removeClass(document.getElementById("search"), "hidden"); removeClass(document.getElementById("search"), "hidden");
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value, history.replaceState(search_input.value,
@ -2407,7 +2406,7 @@ if (!DOMTokenList.prototype.remove) {
var params = getQueryStringParams(); var params = getQueryStringParams();
if (params && params.search) { if (params && params.search) {
addClass(document.getElementById("main"), "hidden"); addClass(main, "hidden");
var search = document.getElementById("search"); var search = document.getElementById("search");
removeClass(search, "hidden"); removeClass(search, "hidden");
search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>"; search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>";
@ -2429,23 +2428,18 @@ if (!DOMTokenList.prototype.remove) {
hideSidebar(); hideSidebar();
}; };
console.log('16', Date.now() - start);
autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true"); autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
console.log('17', Date.now() - start);
if (window.location.hash && window.location.hash.length > 0) { if (window.location.hash && window.location.hash.length > 0) {
expandSection(window.location.hash.replace(/^#/, "")); expandSection(window.location.hash.replace(/^#/, ""));
} }
var main = document.getElementById("main");
if (main) { if (main) {
console.log('18', Date.now() - start); onEach(Array.prototype.slice.call(main.childNodes), function(e) {
onEach(main.childNodes, function(e) {
if (e.tagName === "H2" || e.tagName === "H3") { if (e.tagName === "H2" || e.tagName === "H3") {
e.nextElementSibling.style.display = "block"; e.nextElementSibling.style.display = "block";
} }
}); });
console.log('19', Date.now() - start);
} }
function addSearchOptions(crates) { function addSearchOptions(crates) {