From 854b9d172798ff33472a0ffe2d76cd4605ceeada Mon Sep 17 00:00:00 2001 From: =?utf8?q?D=C3=A1niel=20Buga?= Date: Thu, 31 Dec 2020 10:26:24 +0100 Subject: [PATCH] Collect links into a single vector --- 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 b642f27c0b4..f0dd552f82c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -25,6 +25,7 @@ use rustc_span::edition::Edition; use rustc_span::Span; use std::borrow::Cow; +use std::cell::RefCell; use std::collections::VecDeque; use std::default::Default; use std::fmt::Write; @@ -1132,8 +1133,7 @@ fn push(s: &mut String, text_length: &mut usize, text: &str) { return vec![]; } - let mut links = vec![]; - let mut shortcut_links = vec![]; + let links = RefCell::new(vec![]); let locate = |s: &str, fallback: Range| unsafe { let s_start = s.as_ptr(); @@ -1152,7 +1152,7 @@ fn push(s: &mut String, text_length: &mut usize, text: &str) { let mut push = |link: BrokenLink<'_>| { // FIXME: use `link.span` instead of `locate` // (doing it now includes the `[]` as well as the text) - shortcut_links.push((link.reference.to_owned(), locate(link.reference, link.span))); + links.borrow_mut().push((link.reference.to_owned(), locate(link.reference, link.span))); None }; let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut push)).into_offset_iter(); @@ -1165,16 +1165,14 @@ fn push(s: &mut String, text_length: &mut usize, text: &str) { for ev in iter { if let Event::Start(Tag::Link(_, dest, _)) = ev.0 { debug!("found link: {}", dest); - links.push(match dest { + links.borrow_mut().push(match dest { CowStr::Borrowed(s) => (s.to_owned(), locate(s, ev.1)), s @ (CowStr::Boxed(..) | CowStr::Inlined(..)) => (s.into_string(), ev.1), }); } } - links.append(&mut shortcut_links); - - links + links.into_inner() } #[derive(Debug)] -- 2.44.0