Skip to content

Commit 2f4b4c0

Browse files
authored
Rollup merge of #59452 - GuillaumeGomez:speedup-rustdoc, r=QuietMisdreavus
Speed up rustdoc run a bit r? @QuietMisdreavus
2 parents 4ffddb7 + 7f2c726 commit 2f4b4c0

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
15201520

15211521
[[package]]
15221522
name = "minifier"
1523-
version = "0.0.28"
1523+
version = "0.0.29"
15241524
source = "registry+https://github.com/rust-lang/crates.io-index"
15251525
dependencies = [
15261526
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3039,7 +3039,7 @@ dependencies = [
30393039
name = "rustdoc"
30403040
version = "0.0.0"
30413041
dependencies = [
3042-
"minifier 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
3042+
"minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
30433043
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
30443044
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
30453045
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4149,7 +4149,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41494149
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
41504150
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
41514151
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
4152-
"checksum minifier 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "3a2898502751dcc9d66b6fff57f3cf63cc91605e83e1a33515396f5027f8e4ca"
4152+
"checksum minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4950cb2617b1933e2da0446e864dfe0d6a22c22ff72297996c46e6a63b210b"
41534153
"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649"
41544154
"checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c"
41554155
"checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e"

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ path = "lib.rs"
1010

1111
[dependencies]
1212
pulldown-cmark = { version = "0.1.2", default-features = false }
13-
minifier = "0.0.28"
13+
minifier = "0.0.29"
1414
tempfile = "3"
1515
parking_lot = "0.7"

src/librustdoc/html/render.rs

+47-38
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,11 @@ themePicker.onblur = handleThemeButtonsBlur;
965965
if for_search_index && line.starts_with("var R") {
966966
variables.push(line.clone());
967967
// We need to check if the crate name has been put into a variable as well.
968-
let tokens = js::simple_minify(&line).apply(js::clean_tokens);
968+
let tokens: js::Tokens<'_> = js::simple_minify(&line)
969+
.into_iter()
970+
.filter(js::clean_token)
971+
.collect::<Vec<_>>()
972+
.into();
969973
let mut pos = 0;
970974
while pos < tokens.len() {
971975
if let Some((var_pos, Some(value_pos))) =
@@ -1288,46 +1292,51 @@ fn write_minify_replacer<W: Write>(
12881292
contents: &str,
12891293
enable_minification: bool,
12901294
) -> io::Result<()> {
1291-
use minifier::js::{Keyword, ReservedChar, Token};
1295+
use minifier::js::{simple_minify, Keyword, ReservedChar, Token, Tokens};
12921296

12931297
if enable_minification {
12941298
writeln!(dst, "{}",
1295-
minifier::js::simple_minify(contents)
1296-
.apply(|f| {
1297-
// We keep backlines.
1298-
minifier::js::clean_tokens_except(f, |c| {
1299-
c.get_char() != Some(ReservedChar::Backline)
1300-
})
1301-
})
1302-
.apply(|f| {
1303-
minifier::js::replace_token_with(f, |t| {
1304-
match *t {
1305-
Token::Keyword(Keyword::Null) => Some(Token::Other("N")),
1306-
Token::String(s) => {
1307-
let s = &s[1..s.len() -1]; // The quotes are included
1308-
if s.is_empty() {
1309-
Some(Token::Other("E"))
1310-
} else if s == "t" {
1311-
Some(Token::Other("T"))
1312-
} else if s == "u" {
1313-
Some(Token::Other("U"))
1314-
} else {
1315-
None
1316-
}
1317-
}
1318-
_ => None,
1319-
}
1320-
})
1321-
})
1322-
.apply(|f| {
1323-
// We add a backline after the newly created variables.
1324-
minifier::js::aggregate_strings_into_array_with_separation(
1325-
f,
1326-
"R",
1327-
Token::Char(ReservedChar::Backline),
1328-
)
1329-
})
1330-
.to_string())
1299+
{
1300+
let tokens: Tokens<'_> = simple_minify(contents)
1301+
.into_iter()
1302+
.filter(|f| {
1303+
// We keep backlines.
1304+
minifier::js::clean_token_except(f, &|c: &Token<'_>| {
1305+
c.get_char() != Some(ReservedChar::Backline)
1306+
})
1307+
})
1308+
.map(|f| {
1309+
minifier::js::replace_token_with(f, &|t: &Token<'_>| {
1310+
match *t {
1311+
Token::Keyword(Keyword::Null) => Some(Token::Other("N")),
1312+
Token::String(s) => {
1313+
let s = &s[1..s.len() -1]; // The quotes are included
1314+
if s.is_empty() {
1315+
Some(Token::Other("E"))
1316+
} else if s == "t" {
1317+
Some(Token::Other("T"))
1318+
} else if s == "u" {
1319+
Some(Token::Other("U"))
1320+
} else {
1321+
None
1322+
}
1323+
}
1324+
_ => None,
1325+
}
1326+
})
1327+
})
1328+
.collect::<Vec<_>>()
1329+
.into();
1330+
tokens.apply(|f| {
1331+
// We add a backline after the newly created variables.
1332+
minifier::js::aggregate_strings_into_array_with_separation(
1333+
f,
1334+
"R",
1335+
Token::Char(ReservedChar::Backline),
1336+
)
1337+
})
1338+
.to_string()
1339+
})
13311340
} else {
13321341
writeln!(dst, "{}", contents)
13331342
}

0 commit comments

Comments
 (0)