Skip to content

Commit fcfecab

Browse files
authored
Rollup merge of #95868 - vacuus:markdown-code-blocks, r=GuillaumeGomez
rustdoc: Reduce allocations in a `html::markdown` function
2 parents 78fc931 + 8e15b6c commit fcfecab

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/librustdoc/html/markdown.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
251251
}
252252
}
253253
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
254-
let text = lines.collect::<Vec<Cow<'_, str>>>().join("\n");
254+
let text = lines.intersperse("\n".into()).collect::<String>();
255255

256256
let parse_result = match kind {
257257
CodeBlockKind::Fenced(ref lang) => {
@@ -291,15 +291,13 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
291291
let test = origtext
292292
.lines()
293293
.map(|l| map_line(l).for_code())
294-
.collect::<Vec<Cow<'_, str>>>()
295-
.join("\n");
294+
.intersperse("\n".into())
295+
.collect::<String>();
296296
let krate = krate.as_ref().map(|s| &**s);
297297
let (test, _, _) =
298298
doctest::make_test(&test, krate, false, &Default::default(), edition, None);
299299
let channel = if test.contains("#![feature(") { "&amp;version=nightly" } else { "" };
300300

301-
let edition_string = format!("&amp;edition={}", edition);
302-
303301
// These characters don't need to be escaped in a URI.
304302
// FIXME: use a library function for percent encoding.
305303
fn dont_escape(c: u8) -> bool {
@@ -325,8 +323,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
325323
}
326324
}
327325
Some(format!(
328-
r#"<a class="test-arrow" target="_blank" href="{}?code={}{}{}">Run</a>"#,
329-
url, test_escaped, channel, edition_string
326+
r#"<a class="test-arrow" target="_blank" href="{}?code={}{}&amp;edition={}">Run</a>"#,
327+
url, test_escaped, channel, edition,
330328
))
331329
});
332330

0 commit comments

Comments
 (0)