1
Fork 0

Speed up rustdoc run a bit

This commit is contained in:
Guillaume Gomez 2019-03-27 00:44:35 +01:00
parent 4c27fb19ba
commit 7f2c726d6c
3 changed files with 54 additions and 45 deletions

View file

@ -1500,7 +1500,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "minifier" name = "minifier"
version = "0.0.28" version = "0.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2066,7 +2066,7 @@ name = "rand_chacha"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -2088,7 +2088,7 @@ name = "rand_hc"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -2113,7 +2113,7 @@ name = "rand_xorshift"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -3016,7 +3016,7 @@ dependencies = [
name = "rustdoc" name = "rustdoc"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"minifier 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)", "minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4116,7 +4116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" "checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" "checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum minifier 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "3a2898502751dcc9d66b6fff57f3cf63cc91605e83e1a33515396f5027f8e4ca" "checksum minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4950cb2617b1933e2da0446e864dfe0d6a22c22ff72297996c46e6a63b210b"
"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649" "checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649"
"checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" "checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c"
"checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" "checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e"

View file

@ -10,6 +10,6 @@ path = "lib.rs"
[dependencies] [dependencies]
pulldown-cmark = { version = "0.1.2", default-features = false } pulldown-cmark = { version = "0.1.2", default-features = false }
minifier = "0.0.28" minifier = "0.0.29"
tempfile = "3" tempfile = "3"
parking_lot = "0.7" parking_lot = "0.7"

View file

@ -957,7 +957,11 @@ themePicker.onblur = handleThemeButtonsBlur;
if for_search_index && line.starts_with("var R") { if for_search_index && line.starts_with("var R") {
variables.push(line.clone()); variables.push(line.clone());
// We need to check if the crate name has been put into a variable as well. // We need to check if the crate name has been put into a variable as well.
let tokens = js::simple_minify(&line).apply(js::clean_tokens); let tokens: js::Tokens<'_> = js::simple_minify(&line)
.into_iter()
.filter(js::clean_token)
.collect::<Vec<_>>()
.into();
let mut pos = 0; let mut pos = 0;
while pos < tokens.len() { while pos < tokens.len() {
if let Some((var_pos, Some(value_pos))) = if let Some((var_pos, Some(value_pos))) =
@ -1282,46 +1286,51 @@ fn write_minify_replacer<W: Write>(
contents: &str, contents: &str,
enable_minification: bool, enable_minification: bool,
) -> io::Result<()> { ) -> io::Result<()> {
use minifier::js::{Keyword, ReservedChar, Token}; use minifier::js::{simple_minify, Keyword, ReservedChar, Token, Tokens};
if enable_minification { if enable_minification {
writeln!(dst, "{}", writeln!(dst, "{}",
minifier::js::simple_minify(contents) {
.apply(|f| { let tokens: Tokens<'_> = simple_minify(contents)
// We keep backlines. .into_iter()
minifier::js::clean_tokens_except(f, |c| { .filter(|f| {
c.get_char() != Some(ReservedChar::Backline) // We keep backlines.
}) minifier::js::clean_token_except(f, &|c: &Token<'_>| {
}) c.get_char() != Some(ReservedChar::Backline)
.apply(|f| { })
minifier::js::replace_token_with(f, |t| { })
match *t { .map(|f| {
Token::Keyword(Keyword::Null) => Some(Token::Other("N")), minifier::js::replace_token_with(f, &|t: &Token<'_>| {
Token::String(s) => { match *t {
let s = &s[1..s.len() -1]; // The quotes are included Token::Keyword(Keyword::Null) => Some(Token::Other("N")),
if s.is_empty() { Token::String(s) => {
Some(Token::Other("E")) let s = &s[1..s.len() -1]; // The quotes are included
} else if s == "t" { if s.is_empty() {
Some(Token::Other("T")) Some(Token::Other("E"))
} else if s == "u" { } else if s == "t" {
Some(Token::Other("U")) Some(Token::Other("T"))
} else { } else if s == "u" {
None Some(Token::Other("U"))
} } else {
} None
_ => None, }
} }
}) _ => None,
}) }
.apply(|f| { })
// We add a backline after the newly created variables. })
minifier::js::aggregate_strings_into_array_with_separation( .collect::<Vec<_>>()
f, .into();
"R", tokens.apply(|f| {
Token::Char(ReservedChar::Backline), // We add a backline after the newly created variables.
) minifier::js::aggregate_strings_into_array_with_separation(
}) f,
.to_string()) "R",
Token::Char(ReservedChar::Backline),
)
})
.to_string()
})
} else { } else {
writeln!(dst, "{}", contents) writeln!(dst, "{}", contents)
} }