summary refs log tree commit diff
path: root/src/librustdoc/html/render
diff options
context:
space:
mode:
authorCamelid <camelidcamel@gmail.com>2021-03-01 19:12:03 -0800
committerCamelid <camelidcamel@gmail.com>2021-03-05 19:41:37 -0800
commitc09d9d34f02c72b93da25ba27758db7d7cddb1f4 (patch)
treeb37de07db02a7a62b1415ee89a84d87ec85a8aed /src/librustdoc/html/render
parentff39c46959b0c6926c0199f59f65af585e131e7d (diff)
downloadrust-c09d9d34f02c72b93da25ba27758db7d7cddb1f4.tar.gz
rust-c09d9d34f02c72b93da25ba27758db7d7cddb1f4.zip
Don't unnecessarily clone some fields in `Context`
There was no need to clone `id_map` because it was reset before each
item was rendered. `deref_id_map` was not reset, but it was keyed by
`DefId` and thus was unlikely to have collisions (at least for now).

Now we just clone the fields that need to be cloned, and instead create
fresh versions of the others.
Diffstat (limited to 'src/librustdoc/html/render')
-rw-r--r--src/librustdoc/html/render/context.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 23c2a925105..41d4aef7c7a 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -40,7 +40,6 @@ use crate::html::{layout, sources};
 /// It is intended that this context is a lightweight object which can be fairly
 /// easily cloned because it is cloned per work-job (about once per item in the
 /// rustdoc tree).
-#[derive(Clone)]
 crate struct Context<'tcx> {
     /// Current hierarchy of components leading down to what's currently being
     /// rendered
@@ -157,11 +156,6 @@ impl<'tcx> Context<'tcx> {
             static_extra_scripts: &[],
         };
 
-        {
-            self.id_map.borrow_mut().reset();
-            self.id_map.borrow_mut().populate(&INITIAL_IDS);
-        }
-
         if !self.render_redirect_pages {
             layout::render(
                 &self.shared.layout,
@@ -436,6 +430,21 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
         Ok((cx, krate))
     }
 
+    fn make_child_renderer(&self) -> Self {
+        let mut id_map = IdMap::new();
+        id_map.populate(&INITIAL_IDS);
+
+        Self {
+            current: self.current.clone(),
+            dst: self.dst.clone(),
+            render_redirect_pages: self.render_redirect_pages,
+            id_map: Box::new(RefCell::new(id_map)),
+            deref_id_map: Box::new(RefCell::new(FxHashMap::default())),
+            shared: Rc::clone(&self.shared),
+            cache: Rc::clone(&self.cache),
+        }
+    }
+
     fn after_krate(
         &mut self,
         krate: &clean::Crate,