From 8e15b6cfdeeb36aae27518ce6446452392ebc021 Mon Sep 17 00:00:00 2001 From: Roc Yu Date: Sat, 9 Apr 2022 19:14:29 -0400 Subject: [PATCH] rustdoc: Reduce allocations in a `html::markdown` function --- src/librustdoc/html/markdown.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 3a3d61b1e67cc..943c521485b18 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -251,7 +251,7 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { } } let lines = origtext.lines().filter_map(|l| map_line(l).for_html()); - let text = lines.collect::>>().join("\n"); + let text = lines.intersperse("\n".into()).collect::(); let parse_result = match kind { CodeBlockKind::Fenced(ref lang) => { @@ -291,15 +291,13 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { let test = origtext .lines() .map(|l| map_line(l).for_code()) - .collect::>>() - .join("\n"); + .intersperse("\n".into()) + .collect::(); 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("#![feature(") { "&version=nightly" } else { "" }; - let edition_string = format!("&edition={}", edition); - // These characters don't need to be escaped in a URI. // FIXME: use a library function for percent encoding. fn dont_escape(c: u8) -> bool { @@ -325,8 +323,8 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { } } Some(format!( - r#"Run"#, - url, test_escaped, channel, edition_string + r#"Run"#, + url, test_escaped, channel, edition, )) });