Skip to content

Commit 30c27fd

Browse files
committed
rustdoc: Shrink ItemInner a bit more
It's now even smaller than before I added the `doc_value_cache` to `Attributes`. That's because in addition to boxing the cache field, I also converted `doc_strings` to be a `ThinVec` like the `other_attrs` field already is.
1 parent ce8bf91 commit 30c27fd

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ pub fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
200200
pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
201201
attrs: impl Iterator<Item = (&'a A, Option<DefId>)>,
202202
doc_only: bool,
203-
) -> (Vec<DocFragment>, ThinVec<A>) {
203+
) -> (ThinVec<DocFragment>, ThinVec<A>) {
204204
let (min_size, max_size) = attrs.size_hint();
205205
let size_hint = max_size.unwrap_or(min_size);
206-
let mut doc_fragments = Vec::with_capacity(size_hint);
206+
let mut doc_fragments = ThinVec::with_capacity(size_hint);
207207
let mut other_attrs = ThinVec::<A>::with_capacity(if doc_only { 0 } else { size_hint });
208208
for (attr, item_id) in attrs {
209209
if let Some((doc_str, fragment_kind)) = attr.doc_str_and_fragment_kind() {

src/librustdoc/clean/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,14 +1005,14 @@ pub struct RenderedLink {
10051005
#[derive(Clone, Debug, Default)]
10061006
pub(crate) struct Attributes {
10071007
/// IMPORTANT! This should not be mutated since then `doc_value_cache` will be invalid.
1008-
doc_strings: Vec<DocFragment>,
1008+
doc_strings: ThinVec<DocFragment>,
10091009
pub(crate) other_attrs: ThinVec<hir::Attribute>,
1010-
doc_value_cache: OnceLock<Option<String>>,
1010+
doc_value_cache: Box<OnceLock<Option<Box<str>>>>,
10111011
}
10121012

10131013
impl Attributes {
1014-
fn new(doc_strings: Vec<DocFragment>, other_attrs: ThinVec<hir::Attribute>) -> Self {
1015-
Self { doc_strings, other_attrs, doc_value_cache: OnceLock::new() }
1014+
fn new(doc_strings: ThinVec<DocFragment>, other_attrs: ThinVec<hir::Attribute>) -> Self {
1015+
Self { doc_strings, other_attrs, doc_value_cache: Box::new(OnceLock::new()) }
10161016
}
10171017

10181018
pub(crate) fn doc_strings(&self) -> &[DocFragment] {
@@ -1066,7 +1066,7 @@ impl Attributes {
10661066
add_doc_fragment(&mut res, frag);
10671067
}
10681068
res.pop();
1069-
res
1069+
res.into_boxed_str()
10701070
})
10711071
})
10721072
.as_deref()
@@ -2432,7 +2432,7 @@ mod size_asserts {
24322432
static_assert_size!(GenericParamDef, 40);
24332433
static_assert_size!(Generics, 16);
24342434
static_assert_size!(Item, 8);
2435-
static_assert_size!(ItemInner, 176);
2435+
static_assert_size!(ItemInner, 136);
24362436
static_assert_size!(ItemKind, 48);
24372437
static_assert_size!(PathSegment, 32);
24382438
static_assert_size!(Type, 32);

src/librustdoc/clean/types/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use rustc_span::create_default_session_globals_then;
44

55
use super::*;
66

7-
fn create_doc_fragment(s: &str) -> Vec<DocFragment> {
8-
vec![DocFragment {
7+
fn create_doc_fragment(s: &str) -> ThinVec<DocFragment> {
8+
ThinVec::from([DocFragment {
99
span: DUMMY_SP,
1010
item_id: None,
1111
doc: Symbol::intern(s),
1212
kind: DocFragmentKind::Sugared(CommentKind::Line),
1313
indent: 0,
1414
from_expansion: false,
15-
}]
15+
}])
1616
}
1717

1818
#[track_caller]

0 commit comments

Comments
 (0)