about summary refs log tree commit diff
path: root/src/librustdoc/formats/renderer.rs
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/formats/renderer.rs
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/formats/renderer.rs')
-rw-r--r--src/librustdoc/formats/renderer.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs
index b779363e5c7..9b0d193a0bc 100644
--- a/src/librustdoc/formats/renderer.rs
+++ b/src/librustdoc/formats/renderer.rs
@@ -9,7 +9,7 @@ use crate::formats::cache::Cache;
 /// Allows for different backends to rustdoc to be used with the `run_format()` function. Each
 /// backend renderer has hooks for initialization, documenting an item, entering and exiting a
 /// module, and cleanup/finalizing output.
-crate trait FormatRenderer<'tcx>: Clone {
+crate trait FormatRenderer<'tcx>: Sized {
     /// Gives a description of the renderer. Used for performance profiling.
     fn descr() -> &'static str;
 
@@ -23,6 +23,9 @@ crate trait FormatRenderer<'tcx>: Clone {
         tcx: TyCtxt<'tcx>,
     ) -> Result<(Self, clean::Crate), Error>;
 
+    /// Make a new renderer to render a child of the item currently being rendered.
+    fn make_child_renderer(&self) -> Self;
+
     /// Renders a single non-module item. This means no recursive sub-item rendering is required.
     fn item(&mut self, item: clean::Item) -> Result<(), Error>;
 
@@ -67,7 +70,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
     item.name = Some(krate.name);
 
     // Render the crate documentation
-    let mut work = vec![(format_renderer.clone(), item)];
+    let mut work = vec![(format_renderer.make_child_renderer(), item)];
 
     let unknown = rustc_span::Symbol::intern("<unknown item>");
     while let Some((mut cx, item)) = work.pop() {
@@ -87,7 +90,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
             };
             for it in module.items {
                 debug!("Adding {:?} to worklist", it.name);
-                work.push((cx.clone(), it));
+                work.push((cx.make_child_renderer(), it));
             }
 
             cx.mod_item_out(&name)?;