diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-03-27 00:44:35 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-03-27 19:07:48 +0100 |
| commit | 7f2c726d6cbe14a135ca9b008ca7cc031faae97f (patch) | |
| tree | 7f27bec713b9948e1b45ba78d6ab97085d8c39e2 /src | |
| parent | 4c27fb19ba15a2e45485e601a79914c6280196b0 (diff) | |
| download | rust-7f2c726d6cbe14a135ca9b008ca7cc031faae97f.tar.gz rust-7f2c726d6cbe14a135ca9b008ca7cc031faae97f.zip | |
Speed up rustdoc run a bit
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 85 |
2 files changed, 48 insertions, 39 deletions
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index a8c9166591d..4d2c03a4f2f 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -10,6 +10,6 @@ path = "lib.rs" [dependencies] pulldown-cmark = { version = "0.1.2", default-features = false } -minifier = "0.0.28" +minifier = "0.0.29" tempfile = "3" parking_lot = "0.7" diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index bead4c78e47..948d405c5b9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -957,7 +957,11 @@ themePicker.onblur = handleThemeButtonsBlur; if for_search_index && line.starts_with("var R") { variables.push(line.clone()); // 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; while pos < tokens.len() { if let Some((var_pos, Some(value_pos))) = @@ -1282,46 +1286,51 @@ fn write_minify_replacer<W: Write>( contents: &str, enable_minification: bool, ) -> io::Result<()> { - use minifier::js::{Keyword, ReservedChar, Token}; + use minifier::js::{simple_minify, Keyword, ReservedChar, Token, Tokens}; if enable_minification { writeln!(dst, "{}", - minifier::js::simple_minify(contents) - .apply(|f| { - // We keep backlines. - minifier::js::clean_tokens_except(f, |c| { - c.get_char() != Some(ReservedChar::Backline) - }) - }) - .apply(|f| { - minifier::js::replace_token_with(f, |t| { - match *t { - Token::Keyword(Keyword::Null) => Some(Token::Other("N")), - Token::String(s) => { - let s = &s[1..s.len() -1]; // The quotes are included - if s.is_empty() { - Some(Token::Other("E")) - } else if s == "t" { - Some(Token::Other("T")) - } else if s == "u" { - Some(Token::Other("U")) - } else { - None - } - } - _ => None, - } - }) - }) - .apply(|f| { - // We add a backline after the newly created variables. - minifier::js::aggregate_strings_into_array_with_separation( - f, - "R", - Token::Char(ReservedChar::Backline), - ) - }) - .to_string()) + { + let tokens: Tokens<'_> = simple_minify(contents) + .into_iter() + .filter(|f| { + // We keep backlines. + minifier::js::clean_token_except(f, &|c: &Token<'_>| { + c.get_char() != Some(ReservedChar::Backline) + }) + }) + .map(|f| { + minifier::js::replace_token_with(f, &|t: &Token<'_>| { + match *t { + Token::Keyword(Keyword::Null) => Some(Token::Other("N")), + Token::String(s) => { + let s = &s[1..s.len() -1]; // The quotes are included + if s.is_empty() { + Some(Token::Other("E")) + } else if s == "t" { + Some(Token::Other("T")) + } else if s == "u" { + Some(Token::Other("U")) + } else { + None + } + } + _ => None, + } + }) + }) + .collect::<Vec<_>>() + .into(); + tokens.apply(|f| { + // We add a backline after the newly created variables. + minifier::js::aggregate_strings_into_array_with_separation( + f, + "R", + Token::Char(ReservedChar::Backline), + ) + }) + .to_string() + }) } else { writeln!(dst, "{}", contents) } |
