about summary refs log tree commit diff
path: root/src/librustdoc/html/render
diff options
context:
space:
mode:
authorJustus K <justus.k@protonmail.com>2021-06-26 20:47:33 +0200
committerJustus K <justus.k@protonmail.com>2021-07-05 19:51:51 +0200
commit45d3daece364e4cf6b6bc4668dcfd7670197b1e8 (patch)
tree6c6dad674e0b7ba6e4991f554b492f8b3ec6bef8 /src/librustdoc/html/render
parentacd4dc2d0ca8676fbf105507504e24d44e5dd1f6 (diff)
downloadrust-45d3daece364e4cf6b6bc4668dcfd7670197b1e8.tar.gz
rust-45d3daece364e4cf6b6bc4668dcfd7670197b1e8.zip
rustdoc: Store DefId's in ItemId on heap for decreasing Item's size
Diffstat (limited to 'src/librustdoc/html/render')
-rw-r--r--src/librustdoc/html/render/mod.rs21
-rw-r--r--src/librustdoc/html/render/print_item.rs36
2 files changed, 33 insertions, 24 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 97ee682c11c..1cee68baff4 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -753,7 +753,7 @@ fn assoc_const(
         w,
         "{}{}const <a href=\"{}\" class=\"constant\"><b>{}</b></a>: {}",
         extra,
-        it.visibility.print_with_space(it.def_id, cx),
+        it.visibility.print_with_space(it.def_id.clone(), cx),
         naive_assoc_href(it, link, cx),
         it.name.as_ref().unwrap(),
         ty.print(cx)
@@ -872,7 +872,7 @@ fn render_assoc_item(
                     .unwrap_or_else(|| format!("#{}.{}", ty, name))
             }
         };
-        let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
+        let vis = meth.visibility.print_with_space(meth.def_id.clone(), cx).to_string();
         let constness =
             print_constness_with_space(&header.constness, meth.const_stability(cx.tcx()));
         let asyncness = header.asyncness.print_with_space();
@@ -984,7 +984,7 @@ fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item) {
     }
 }
 
-#[derive(Copy, Clone)]
+#[derive(Clone)]
 enum AssocItemLink<'a> {
     Anchor(Option<&'a str>),
     GotoSource(ItemId, &'a FxHashSet<Symbol>),
@@ -994,7 +994,7 @@ impl<'a> AssocItemLink<'a> {
     fn anchor(&self, id: &'a str) -> Self {
         match *self {
             AssocItemLink::Anchor(_) => AssocItemLink::Anchor(Some(&id)),
-            ref other => *other,
+            ref other => other.clone(),
         }
     }
 }
@@ -1306,7 +1306,14 @@ fn render_impl(
                         } else {
                             // In case the item isn't documented,
                             // provide short documentation from the trait.
-                            document_short(&mut doc_buffer, it, cx, link, parent, show_def_docs);
+                            document_short(
+                                &mut doc_buffer,
+                                it,
+                                cx,
+                                link.clone(),
+                                parent,
+                                show_def_docs,
+                            );
                         }
                     }
                 } else {
@@ -1317,7 +1324,7 @@ fn render_impl(
                     }
                 }
             } else {
-                document_short(&mut doc_buffer, item, cx, link, parent, show_def_docs);
+                document_short(&mut doc_buffer, item, cx, link.clone(), parent, show_def_docs);
             }
         }
         let w = if short_documented && trait_.is_some() { interesting } else { boring };
@@ -1445,7 +1452,7 @@ fn render_impl(
             trait_item,
             if trait_.is_some() { &i.impl_item } else { parent },
             parent,
-            link,
+            link.clone(),
             render_mode,
             false,
             trait_.map(|t| &t.trait_),
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index eeac9d1a9db..70e80b20b2a 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -245,7 +245,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
     // (which is the position in the vector).
     indices.dedup_by_key(|i| {
         (
-            items[*i].def_id,
+            items[*i].def_id.clone(),
             if items[*i].name.as_ref().is_some() { Some(full_path(cx, &items[*i])) } else { None },
             items[*i].type_(),
             if items[*i].is_import() { *i } else { 0 },
@@ -288,14 +288,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
                     Some(ref src) => write!(
                         w,
                         "<div class=\"item-left\"><code>{}extern crate {} as {};",
-                        myitem.visibility.print_with_space(myitem.def_id, cx),
+                        myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
                         anchor(myitem.def_id.expect_def_id(), &*src.as_str(), cx),
                         myitem.name.as_ref().unwrap(),
                     ),
                     None => write!(
                         w,
                         "<div class=\"item-left\"><code>{}extern crate {};",
-                        myitem.visibility.print_with_space(myitem.def_id, cx),
+                        myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
                         anchor(
                             myitem.def_id.expect_def_id(),
                             &*myitem.name.as_ref().unwrap().as_str(),
@@ -336,7 +336,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
                      <div class=\"item-right docblock-short\">{stab_tags}</div>",
                     stab = stab.unwrap_or_default(),
                     add = add,
-                    vis = myitem.visibility.print_with_space(myitem.def_id, cx),
+                    vis = myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
                     imp = import.print(cx),
                     stab_tags = stab_tags.unwrap_or_default(),
                 );
@@ -437,7 +437,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
 }
 
 fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
-    let vis = it.visibility.print_with_space(it.def_id, cx).to_string();
+    let vis = it.visibility.print_with_space(it.def_id.clone(), cx).to_string();
     let constness = print_constness_with_space(&f.header.constness, it.const_stability(cx.tcx()));
     let asyncness = f.header.asyncness.print_with_space();
     let unsafety = f.header.unsafety.print_with_space();
@@ -489,7 +489,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
         write!(
             w,
             "{}{}{}trait {}{}{}",
-            it.visibility.print_with_space(it.def_id, cx),
+            it.visibility.print_with_space(it.def_id.clone(), cx),
             t.unsafety.print_with_space(),
             if t.is_auto { "auto " } else { "" },
             it.name.as_ref().unwrap(),
@@ -710,8 +710,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
 
             for implementor in foreign {
                 let provided_methods = implementor.inner_impl().provided_trait_methods(cx.tcx());
-                let assoc_link =
-                    AssocItemLink::GotoSource(implementor.impl_item.def_id, &provided_methods);
+                let assoc_link = AssocItemLink::GotoSource(
+                    implementor.impl_item.def_id.clone(),
+                    &provided_methods,
+                );
                 render_impl(
                     w,
                     cx,
@@ -915,7 +917,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
         write!(
             w,
             "{}enum {}{}{}",
-            it.visibility.print_with_space(it.def_id, cx),
+            it.visibility.print_with_space(it.def_id.clone(), cx),
             it.name.as_ref().unwrap(),
             e.generics.print(cx),
             print_where_clause(&e.generics, cx, 0, true),
@@ -1103,7 +1105,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
     write!(
         w,
         "{vis}const {name}: {typ}",
-        vis = it.visibility.print_with_space(it.def_id, cx),
+        vis = it.visibility.print_with_space(it.def_id.clone(), cx),
         name = it.name.as_ref().unwrap(),
         typ = c.type_.print(cx),
     );
@@ -1193,7 +1195,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
     write!(
         w,
         "{vis}static {mutability}{name}: {typ}</pre>",
-        vis = it.visibility.print_with_space(it.def_id, cx),
+        vis = it.visibility.print_with_space(it.def_id.clone(), cx),
         mutability = s.mutability.print_with_space(),
         name = it.name.as_ref().unwrap(),
         typ = s.type_.print(cx)
@@ -1207,7 +1209,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
     write!(
         w,
         "    {}type {};\n}}</pre>",
-        it.visibility.print_with_space(it.def_id, cx),
+        it.visibility.print_with_space(it.def_id.clone(), cx),
         it.name.as_ref().unwrap(),
     );
 
@@ -1362,7 +1364,7 @@ fn render_union(
     write!(
         w,
         "{}{}{}",
-        it.visibility.print_with_space(it.def_id, cx),
+        it.visibility.print_with_space(it.def_id.clone(), cx),
         if structhead { "union " } else { "" },
         it.name.as_ref().unwrap()
     );
@@ -1384,7 +1386,7 @@ fn render_union(
             write!(
                 w,
                 "    {}{}: {},\n{}",
-                field.visibility.print_with_space(field.def_id, cx),
+                field.visibility.print_with_space(field.def_id.clone(), cx),
                 field.name.as_ref().unwrap(),
                 ty.print(cx),
                 tab
@@ -1414,7 +1416,7 @@ fn render_struct(
     write!(
         w,
         "{}{}{}",
-        it.visibility.print_with_space(it.def_id, cx),
+        it.visibility.print_with_space(it.def_id.clone(), cx),
         if structhead { "struct " } else { "" },
         it.name.as_ref().unwrap()
     );
@@ -1440,7 +1442,7 @@ fn render_struct(
                         w,
                         "\n{}    {}{}: {},",
                         tab,
-                        field.visibility.print_with_space(field.def_id, cx),
+                        field.visibility.print_with_space(field.def_id.clone(), cx),
                         field.name.as_ref().unwrap(),
                         ty.print(cx),
                     );
@@ -1474,7 +1476,7 @@ fn render_struct(
                         write!(
                             w,
                             "{}{}",
-                            field.visibility.print_with_space(field.def_id, cx),
+                            field.visibility.print_with_space(field.def_id.clone(), cx),
                             ty.print(cx),
                         )
                     }