Auto merge of #56005 - GuillaumeGomez:speedup-doc-render, r=QuietMisdreavus
Greatly improve rustdoc rendering speed issues Fixes #55900. So a few improvements here: * we're switching to `DOMTokenList` API when available providing a replacement if it isn't (should only happen on safari and IE I think...) * hide doc sections by default to allow the whole HTML generation to happen in the background to avoid triggering DOM redraw all the times (which killed the performances) r? @QuietMisdreavus
This commit is contained in:
commit
7f04a646c6
7 changed files with 688 additions and 612 deletions
File diff suppressed because it is too large
Load diff
19
src/librustdoc/html/static/noscript.css
Normal file
19
src/librustdoc/html/static/noscript.css
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
* file at the top-level directory of this distribution and at
|
||||
* http://rust-lang.org/COPYRIGHT.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
* option. This file may not be copied, modified, or distributed
|
||||
* except according to those terms.
|
||||
*/
|
||||
|
||||
#main > h2 + div, #main > h2 + h3, #main > h3 + div {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.loading-content {
|
||||
display: none;
|
||||
}
|
||||
|
|
@ -368,6 +368,10 @@ body:not(.source) .example-wrap > pre {
|
|||
#main > .docblock h2 { font-size: 1.15em; }
|
||||
#main > .docblock h3, #main > .docblock h4, #main > .docblock h5 { font-size: 1em; }
|
||||
|
||||
#main > h2 + div, #main > h2 + h3, #main > h3 + div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.docblock h1 { font-size: 1em; }
|
||||
.docblock h2 { font-size: 0.95em; }
|
||||
.docblock h3, .docblock h4, .docblock h5 { font-size: 0.9em; }
|
||||
|
|
|
|||
|
|
@ -19,55 +19,38 @@ var mainTheme = document.getElementById("mainThemeStyle");
|
|||
var savedHref = [];
|
||||
|
||||
function hasClass(elem, className) {
|
||||
if (elem && className && elem.className) {
|
||||
var elemClass = elem.className;
|
||||
var start = elemClass.indexOf(className);
|
||||
if (start === -1) {
|
||||
return false;
|
||||
} else if (elemClass.length === className.length) {
|
||||
return true;
|
||||
} else {
|
||||
if (start > 0 && elemClass[start - 1] !== ' ') {
|
||||
return false;
|
||||
}
|
||||
var end = start + className.length;
|
||||
return !(end < elemClass.length && elemClass[end] !== ' ');
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return elem && elem.classList && elem.classList.contains(className);
|
||||
}
|
||||
|
||||
function addClass(elem, className) {
|
||||
if (elem && className && !hasClass(elem, className)) {
|
||||
if (elem.className && elem.className.length > 0) {
|
||||
elem.className += ' ' + className;
|
||||
} else {
|
||||
elem.className = className;
|
||||
}
|
||||
if (!elem || !elem.classList) {
|
||||
return;
|
||||
}
|
||||
elem.classList.add(className);
|
||||
}
|
||||
|
||||
function removeClass(elem, className) {
|
||||
if (elem && className && elem.className) {
|
||||
elem.className = (" " + elem.className + " ").replace(" " + className + " ", " ")
|
||||
.trim();
|
||||
if (!elem || !elem.classList) {
|
||||
return;
|
||||
}
|
||||
elem.classList.remove(className);
|
||||
}
|
||||
|
||||
function isHidden(elem) {
|
||||
return (elem.offsetParent === null)
|
||||
return elem.offsetParent === null;
|
||||
}
|
||||
|
||||
function onEach(arr, func, reversed) {
|
||||
if (arr && arr.length > 0 && func) {
|
||||
var length = arr.length;
|
||||
if (reversed !== true) {
|
||||
for (var i = 0; i < arr.length; ++i) {
|
||||
for (var i = 0; i < length; ++i) {
|
||||
if (func(arr[i]) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = arr.length - 1; i >= 0; --i) {
|
||||
for (var i = length - 1; i >= 0; --i) {
|
||||
if (func(arr[i]) === true) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -77,6 +60,13 @@ function onEach(arr, func, reversed) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function onEachLazy(lazyArray, func, reversed) {
|
||||
return onEach(
|
||||
Array.prototype.slice.call(lazyArray),
|
||||
func,
|
||||
reversed);
|
||||
}
|
||||
|
||||
function usableLocalStorage() {
|
||||
// Check if the browser supports localStorage at all:
|
||||
if (typeof(Storage) === "undefined") {
|
||||
|
|
@ -133,8 +123,8 @@ function switchTheme(styleElem, mainStyleElem, newTheme) {
|
|||
});
|
||||
if (found === true) {
|
||||
styleElem.href = newHref;
|
||||
updateLocalStorage('rustdoc-theme', newTheme);
|
||||
updateLocalStorage("rustdoc-theme", newTheme);
|
||||
}
|
||||
}
|
||||
|
||||
switchTheme(currentTheme, mainTheme, getCurrentValue('rustdoc-theme') || 'light');
|
||||
switchTheme(currentTheme, mainTheme, getCurrentValue("rustdoc-theme") || "light");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue