about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-08-15 16:13:53 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2024-10-03 11:12:19 +0200
commit47f40d468acae7e37d101cee9a6d79bff3461c64 (patch)
tree15f4a53a4a4d5bfd345a11fba3a9b84afa640cb9
parente0b0851ba8a83d4f258a9d86ba5579c4f2c61b46 (diff)
downloadrust-47f40d468acae7e37d101cee9a6d79bff3461c64.tar.gz
rust-47f40d468acae7e37d101cee9a6d79bff3461c64.zip
Improve rendering speed by moving settings generation after theme rendering
-rw-r--r--tests/compile-test.rs11
-rw-r--r--util/gh-pages/index_template.html4
-rw-r--r--util/gh-pages/script.js49
3 files changed, 36 insertions, 28 deletions
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
index 00627dc0bb1..162aed393c4 100644
--- a/tests/compile-test.rs
+++ b/tests/compile-test.rs
@@ -9,7 +9,8 @@ use clippy_lints::LintInfo;
 use clippy_lints::declared_lints::LINTS;
 use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
 use pulldown_cmark::{Options, Parser, html};
-use rinja::{Template, filters::Safe};
+use rinja::Template;
+use rinja::filters::Safe;
 use serde::Deserialize;
 use test_utils::IS_RUSTC_TEST_SUITE;
 use ui_test::custom_flags::Flag;
@@ -394,7 +395,7 @@ struct Renderer<'a> {
 }
 
 impl<'a> Renderer<'a> {
-    fn markdown(&self, input: &str) -> Safe<String> {
+    fn markdown(input: &str) -> Safe<String> {
         let parser = Parser::new_ext(input, Options::all());
         let mut html_output = String::new();
         html::push_html(&mut html_output, parser);
@@ -465,7 +466,11 @@ impl DiagnosticCollector {
                 .collect();
             metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));
 
-            fs::write("util/gh-pages/index.html", Renderer { lints: &metadata }.render().unwrap()).unwrap();
+            fs::write(
+                "util/gh-pages/index.html",
+                Renderer { lints: &metadata }.render().unwrap(),
+            )
+            .unwrap();
         });
 
         (Self { sender }, handle)
diff --git a/util/gh-pages/index_template.html b/util/gh-pages/index_template.html
index 774c7b487c1..d942cbe39e7 100644
--- a/util/gh-pages/index_template.html
+++ b/util/gh-pages/index_template.html
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <!--
 Welcome to a Clippy's lint list, at least the source code of it. If you are
-interested in contributing to this website checkout `util/gh-pages/index.html`
+interested in contributing to this website checkout `util/gh-pages/index_template.html`
 inside the rust-clippy repository.
 
 Otherwise, have a great day =^.^=
@@ -164,7 +164,7 @@ Otherwise, have a great day =^.^=
                     </header>
 
                     <div class="list-group lint-docs">
-                        <div class="list-group-item lint-doc-md">{(markdown(lint.docs))}</div>
+                        <div class="list-group-item lint-doc-md">{(Self::markdown(lint.docs))}</div>
                         <div class="lint-additional-info-container">
                             {# Applicability #}
                             <div class="lint-additional-info-item">
diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js
index d3bc6f6fc99..4264f48e846 100644
--- a/util/gh-pages/script.js
+++ b/util/gh-pages/script.js
@@ -46,17 +46,6 @@ function setTheme(theme, store) {
     }
 }
 
-// loading the theme after the initial load
-const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
-const theme = loadValue('theme');
-if (prefersDark.matches && !theme) {
-    setTheme("coal", false);
-} else {
-    setTheme(theme, false);
-}
-let disableShortcuts = loadValue('disable-shortcuts') === "true";
-document.getElementById("disable-shortcuts").checked = disableShortcuts;
-
 window.searchState = {
     timeout: null,
     inputElem: document.getElementById("search-input"),
@@ -161,9 +150,6 @@ function handleShortcut(ev) {
     }
 }
 
-document.addEventListener("keypress", handleShortcut);
-document.addEventListener("keydown", handleShortcut);
-
 function toggleElements(filter, value) {
     let needsUpdate = false;
     let count = 0;
@@ -271,13 +257,13 @@ const GROUPS_FILTER_DEFAULT = {
     cargo: true,
     complexity: true,
     correctness: true,
-    deprecated: false,
     nursery: true,
     pedantic: true,
     perf: true,
     restriction: true,
     style: true,
     suspicious: true,
+    deprecated: false,
 };
 const LEVEL_FILTERS_DEFAULT = {
     allow: true,
@@ -287,7 +273,6 @@ const LEVEL_FILTERS_DEFAULT = {
 };
 const APPLICABILITIES_FILTER_DEFAULT = {
     Unspecified: true,
-    Unresolved: true,
     MachineApplicable: true,
     MaybeIncorrect: true,
     HasPlaceholders: true,
@@ -570,9 +555,6 @@ function generateSearch() {
     searchState.inputElem.addEventListener("paste", handleInputChanged);
 }
 
-generateSettings();
-generateSearch();
-
 function scrollToLint(lintId) {
     const target = document.getElementById(lintId);
     if (!target) {
@@ -617,7 +599,28 @@ function parseURLFilters() {
     }
 }
 
-parseURLFilters();
-scrollToLintByURL();
-filters.filterLints();
-onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
+// loading the theme after the initial load
+const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
+const theme = loadValue('theme');
+if (prefersDark.matches && !theme) {
+    setTheme("coal", false);
+} else {
+    setTheme(theme, false);
+}
+
+let disableShortcuts = loadValue('disable-shortcuts') === "true";
+// To prevent having a "flash", we give back time to the web browser to finish rendering with
+// theme applied before finishing the rendering.
+setTimeout(() => {
+    document.getElementById("disable-shortcuts").checked = disableShortcuts;
+
+    document.addEventListener("keypress", handleShortcut);
+    document.addEventListener("keydown", handleShortcut);
+
+    generateSettings();
+    generateSearch();
+    parseURLFilters();
+    scrollToLintByURL();
+    filters.filterLints();
+    onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
+}, 0);