Skip to content

Commit 47f40d4

Browse files
Improve rendering speed by moving settings generation after theme rendering
1 parent e0b0851 commit 47f40d4

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

tests/compile-test.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use clippy_lints::LintInfo;
99
use clippy_lints::declared_lints::LINTS;
1010
use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
1111
use pulldown_cmark::{Options, Parser, html};
12-
use rinja::{Template, filters::Safe};
12+
use rinja::Template;
13+
use rinja::filters::Safe;
1314
use serde::Deserialize;
1415
use test_utils::IS_RUSTC_TEST_SUITE;
1516
use ui_test::custom_flags::Flag;
@@ -394,7 +395,7 @@ struct Renderer<'a> {
394395
}
395396

396397
impl<'a> Renderer<'a> {
397-
fn markdown(&self, input: &str) -> Safe<String> {
398+
fn markdown(input: &str) -> Safe<String> {
398399
let parser = Parser::new_ext(input, Options::all());
399400
let mut html_output = String::new();
400401
html::push_html(&mut html_output, parser);
@@ -465,7 +466,11 @@ impl DiagnosticCollector {
465466
.collect();
466467
metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));
467468

468-
fs::write("util/gh-pages/index.html", Renderer { lints: &metadata }.render().unwrap()).unwrap();
469+
fs::write(
470+
"util/gh-pages/index.html",
471+
Renderer { lints: &metadata }.render().unwrap(),
472+
)
473+
.unwrap();
469474
});
470475

471476
(Self { sender }, handle)

util/gh-pages/index_template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<!--
33
Welcome to a Clippy's lint list, at least the source code of it. If you are
4-
interested in contributing to this website checkout `util/gh-pages/index.html`
4+
interested in contributing to this website checkout `util/gh-pages/index_template.html`
55
inside the rust-clippy repository.
66
77
Otherwise, have a great day =^.^=
@@ -164,7 +164,7 @@ <h2 class="panel-title">
164164
</header>
165165

166166
<div class="list-group lint-docs">
167-
<div class="list-group-item lint-doc-md">{(markdown(lint.docs))}</div>
167+
<div class="list-group-item lint-doc-md">{(Self::markdown(lint.docs))}</div>
168168
<div class="lint-additional-info-container">
169169
{# Applicability #}
170170
<div class="lint-additional-info-item">

util/gh-pages/script.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@ function setTheme(theme, store) {
4646
}
4747
}
4848

49-
// loading the theme after the initial load
50-
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
51-
const theme = loadValue('theme');
52-
if (prefersDark.matches && !theme) {
53-
setTheme("coal", false);
54-
} else {
55-
setTheme(theme, false);
56-
}
57-
let disableShortcuts = loadValue('disable-shortcuts') === "true";
58-
document.getElementById("disable-shortcuts").checked = disableShortcuts;
59-
6049
window.searchState = {
6150
timeout: null,
6251
inputElem: document.getElementById("search-input"),
@@ -161,9 +150,6 @@ function handleShortcut(ev) {
161150
}
162151
}
163152

164-
document.addEventListener("keypress", handleShortcut);
165-
document.addEventListener("keydown", handleShortcut);
166-
167153
function toggleElements(filter, value) {
168154
let needsUpdate = false;
169155
let count = 0;
@@ -271,13 +257,13 @@ const GROUPS_FILTER_DEFAULT = {
271257
cargo: true,
272258
complexity: true,
273259
correctness: true,
274-
deprecated: false,
275260
nursery: true,
276261
pedantic: true,
277262
perf: true,
278263
restriction: true,
279264
style: true,
280265
suspicious: true,
266+
deprecated: false,
281267
};
282268
const LEVEL_FILTERS_DEFAULT = {
283269
allow: true,
@@ -287,7 +273,6 @@ const LEVEL_FILTERS_DEFAULT = {
287273
};
288274
const APPLICABILITIES_FILTER_DEFAULT = {
289275
Unspecified: true,
290-
Unresolved: true,
291276
MachineApplicable: true,
292277
MaybeIncorrect: true,
293278
HasPlaceholders: true,
@@ -570,9 +555,6 @@ function generateSearch() {
570555
searchState.inputElem.addEventListener("paste", handleInputChanged);
571556
}
572557

573-
generateSettings();
574-
generateSearch();
575-
576558
function scrollToLint(lintId) {
577559
const target = document.getElementById(lintId);
578560
if (!target) {
@@ -617,7 +599,28 @@ function parseURLFilters() {
617599
}
618600
}
619601

620-
parseURLFilters();
621-
scrollToLintByURL();
622-
filters.filterLints();
623-
onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
602+
// loading the theme after the initial load
603+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
604+
const theme = loadValue('theme');
605+
if (prefersDark.matches && !theme) {
606+
setTheme("coal", false);
607+
} else {
608+
setTheme(theme, false);
609+
}
610+
611+
let disableShortcuts = loadValue('disable-shortcuts') === "true";
612+
// To prevent having a "flash", we give back time to the web browser to finish rendering with
613+
// theme applied before finishing the rendering.
614+
setTimeout(() => {
615+
document.getElementById("disable-shortcuts").checked = disableShortcuts;
616+
617+
document.addEventListener("keypress", handleShortcut);
618+
document.addEventListener("keydown", handleShortcut);
619+
620+
generateSettings();
621+
generateSearch();
622+
parseURLFilters();
623+
scrollToLintByURL();
624+
filters.filterLints();
625+
onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
626+
}, 0);

0 commit comments

Comments
 (0)