Skip to content

Commit

Permalink
Rollup merge of #95868 - vacuus:markdown-code-blocks, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
rustdoc: Reduce allocations in a `html::markdown` function
  • Loading branch information
Dylan-DPC authored Apr 10, 2022
2 parents 78fc931 + 8e15b6c commit fcfecab
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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("#![feature(") { "&amp;version=nightly" } else { "" };

let edition_string = format!("&amp;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 {
Expand All @@ -325,8 +323,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
}
}
Some(format!(
r#"<a class="test-arrow" target="_blank" href="{}?code={}{}{}">Run</a>"#,
url, test_escaped, channel, edition_string
r#"<a class="test-arrow" target="_blank" href="{}?code={}{}&amp;edition={}">Run</a>"#,
url, test_escaped, channel, edition,
))
});

Expand Down

0 comments on commit fcfecab

Please sign in to comment.