Skip to content

Commit 7f2c726

Browse files
Speed up rustdoc run a bit
1 parent 4c27fb1 commit 7f2c726

File tree

3 files changed

+54
-45
lines changed

3 files changed

+54
-45
lines changed

Cargo.lock

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

15011501
[[package]]
15021502
name = "minifier"
1503-
version = "0.0.28"
1503+
version = "0.0.29"
15041504
source = "registry+https://github.com/rust-lang/crates.io-index"
15051505
dependencies = [
15061506
"macro-utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2066,7 +2066,7 @@ name = "rand_chacha"
20662066
version = "0.1.0"
20672067
source = "registry+https://github.com/rust-lang/crates.io-index"
20682068
dependencies = [
2069-
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
2069+
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
20702070
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
20712071
]
20722072

@@ -2088,7 +2088,7 @@ name = "rand_hc"
20882088
version = "0.1.0"
20892089
source = "registry+https://github.com/rust-lang/crates.io-index"
20902090
dependencies = [
2091-
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
2091+
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
20922092
]
20932093

20942094
[[package]]
@@ -2113,7 +2113,7 @@ name = "rand_xorshift"
21132113
version = "0.1.0"
21142114
source = "registry+https://github.com/rust-lang/crates.io-index"
21152115
dependencies = [
2116-
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
2116+
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
21172117
]
21182118

21192119
[[package]]
@@ -3016,7 +3016,7 @@ dependencies = [
30163016
name = "rustdoc"
30173017
version = "0.0.0"
30183018
dependencies = [
3019-
"minifier 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
3019+
"minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
30203020
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
30213021
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
30223022
"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"
41164116
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
41174117
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
41184118
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
4119-
"checksum minifier 0.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "3a2898502751dcc9d66b6fff57f3cf63cc91605e83e1a33515396f5027f8e4ca"
4119+
"checksum minifier 0.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4950cb2617b1933e2da0446e864dfe0d6a22c22ff72297996c46e6a63b210b"
41204120
"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649"
41214121
"checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c"
41224122
"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
@@ -957,7 +957,11 @@ themePicker.onblur = handleThemeButtonsBlur;
957957
if for_search_index && line.starts_with("var R") {
958958
variables.push(line.clone());
959959
// We need to check if the crate name has been put into a variable as well.
960-
let tokens = js::simple_minify(&line).apply(js::clean_tokens);
960+
let tokens: js::Tokens<'_> = js::simple_minify(&line)
961+
.into_iter()
962+
.filter(js::clean_token)
963+
.collect::<Vec<_>>()
964+
.into();
961965
let mut pos = 0;
962966
while pos < tokens.len() {
963967
if let Some((var_pos, Some(value_pos))) =
@@ -1282,46 +1286,51 @@ fn write_minify_replacer<W: Write>(
12821286
contents: &str,
12831287
enable_minification: bool,
12841288
) -> io::Result<()> {
1285-
use minifier::js::{Keyword, ReservedChar, Token};
1289+
use minifier::js::{simple_minify, Keyword, ReservedChar, Token, Tokens};
12861290

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

0 commit comments

Comments
 (0)