diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-04-10 21:03:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-10 21:03:39 +0200 |
| commit | fcfecab2d8144005404f4d88a840ee24503d87f3 (patch) | |
| tree | 2ed06f4c5f3421e6951234a3ca7a053fbad38a42 /src | |
| parent | 78fc931355e9449eae5a1370d3f078f4e780446c (diff) | |
| parent | 8e15b6cfdeeb36aae27518ce6446452392ebc021 (diff) | |
| download | rust-fcfecab2d8144005404f4d88a840ee24503d87f3.tar.gz rust-fcfecab2d8144005404f4d88a840ee24503d87f3.zip | |
Rollup merge of #95868 - vacuus:markdown-code-blocks, r=GuillaumeGomez
rustdoc: Reduce allocations in a `html::markdown` function
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 3a3d61b1e67..943c521485b 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -251,7 +251,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { } } let lines = origtext.lines().filter_map(|l| map_line(l).for_html()); - let text = lines.collect::<Vec<Cow<'_, str>>>().join("\n"); + let text = lines.intersperse("\n".into()).collect::<String>(); let parse_result = match kind { CodeBlockKind::Fenced(ref lang) => { @@ -291,15 +291,13 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { let test = origtext .lines() .map(|l| map_line(l).for_code()) - .collect::<Vec<Cow<'_, str>>>() - .join("\n"); + .intersperse("\n".into()) + .collect::<String>(); let krate = krate.as_ref().map(|s| &**s); let (test, _, _) = doctest::make_test(&test, krate, false, &Default::default(), edition, None); let channel = if test.contains("#