Skip to content

Commit a69d434

Browse files
committed
rustdoc: use ThinVec and Box<str> to shrink clean::ItemKind
1 parent 0950848 commit a69d434

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::iter::once;
44
use std::sync::Arc;
55

6-
use thin_vec::ThinVec;
6+
use thin_vec::{thin_vec, ThinVec};
77

88
use rustc_ast as ast;
99
use rustc_data_structures::fx::FxHashSet;
@@ -596,7 +596,7 @@ fn build_module_items(
596596
clean::ImportSource {
597597
path: clean::Path {
598598
res,
599-
segments: vec![clean::PathSegment {
599+
segments: thin_vec![clean::PathSegment {
600600
name: prim_ty.as_sym(),
601601
args: clean::GenericArgs::AngleBracketed {
602602
args: Default::default(),

src/librustdoc/clean/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub(crate) fn clean_middle_const<'tcx>(
227227
// FIXME: instead of storing the stringified expression, store `self` directly instead.
228228
Constant {
229229
type_: clean_middle_ty(constant.ty(), cx, None),
230-
kind: ConstantKind::TyConst { expr: constant.to_string() },
230+
kind: ConstantKind::TyConst { expr: constant.to_string().into() },
231231
}
232232
}
233233

@@ -1200,7 +1200,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
12001200
true
12011201
}
12021202
(GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &c.kind {
1203-
ConstantKind::TyConst { expr } => expr == param.name.as_str(),
1203+
ConstantKind::TyConst { expr } => **expr == *param.name.as_str(),
12041204
_ => false,
12051205
},
12061206
_ => false,
@@ -1529,7 +1529,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
15291529
}
15301530
};
15311531

1532-
Array(Box::new(clean_ty(ty, cx)), length)
1532+
Array(Box::new(clean_ty(ty, cx)), length.into())
15331533
}
15341534
TyKind::Tup(tys) => Tuple(tys.iter().map(|ty| clean_ty(ty, cx)).collect()),
15351535
TyKind::OpaqueDef(item_id, _, _) => {
@@ -1601,7 +1601,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
16011601
ty::Array(ty, mut n) => {
16021602
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
16031603
let n = print_const(cx, n);
1604-
Array(Box::new(clean_middle_ty(ty, cx, None)), n)
1604+
Array(Box::new(clean_middle_ty(ty, cx, None)), n.into())
16051605
}
16061606
ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(clean_middle_ty(mt.ty, cx, None))),
16071607
ty::Ref(r, ty, mutbl) => BorrowedRef {

src/librustdoc/clean/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ pub(crate) enum Type {
16211621
/// An array type.
16221622
///
16231623
/// The `String` field is a stringified version of the array's length parameter.
1624-
Array(Box<Type>, String),
1624+
Array(Box<Type>, Box<str>),
16251625
/// A raw pointer type: `*const i32`, `*mut i32`
16261626
RawPointer(Mutability, Box<Type>),
16271627
/// A reference type: `&i32`, `&'a mut Foo`
@@ -2206,7 +2206,7 @@ impl Span {
22062206
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
22072207
pub(crate) struct Path {
22082208
pub(crate) res: Res,
2209-
pub(crate) segments: Vec<PathSegment>,
2209+
pub(crate) segments: ThinVec<PathSegment>,
22102210
}
22112211

22122212
impl Path {
@@ -2356,7 +2356,7 @@ pub(crate) enum ConstantKind {
23562356
///
23572357
/// Note that `ty::Const` includes generic parameters, and may not always be uniquely identified
23582358
/// by a DefId. So this field must be different from `Extern`.
2359-
TyConst { expr: String },
2359+
TyConst { expr: Box<str> },
23602360
/// A constant (expression) that's not an item or associated item. These are usually found
23612361
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
23622362
/// used to define explicit discriminant values for enum variants.
@@ -2384,7 +2384,7 @@ impl Constant {
23842384
impl ConstantKind {
23852385
pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String {
23862386
match *self {
2387-
ConstantKind::TyConst { ref expr } => expr.clone(),
2387+
ConstantKind::TyConst { ref expr } => expr.to_string(),
23882388
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
23892389
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
23902390
print_const_expr(tcx, body)
@@ -2570,13 +2570,13 @@ mod size_asserts {
25702570
// tidy-alphabetical-start
25712571
static_assert_size!(Crate, 72); // frequently moved by-value
25722572
static_assert_size!(DocFragment, 32);
2573-
static_assert_size!(GenericArg, 48);
2573+
static_assert_size!(GenericArg, 32);
25742574
static_assert_size!(GenericArgs, 32);
25752575
static_assert_size!(GenericParamDef, 56);
25762576
static_assert_size!(Generics, 16);
25772577
static_assert_size!(Item, 56);
2578-
static_assert_size!(ItemKind, 88);
2578+
static_assert_size!(ItemKind, 64);
25792579
static_assert_size!(PathSegment, 40);
2580-
static_assert_size!(Type, 48);
2580+
static_assert_size!(Type, 32);
25812581
// tidy-alphabetical-end
25822582
}

src/librustdoc/clean/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{self, DefIdTree, TyCtxt};
2121
use rustc_span::symbol::{kw, sym, Symbol};
2222
use std::fmt::Write as _;
2323
use std::mem;
24-
use thin_vec::ThinVec;
24+
use thin_vec::{thin_vec, ThinVec};
2525

2626
#[cfg(test)]
2727
mod tests;
@@ -136,7 +136,7 @@ pub(super) fn external_path<'tcx>(
136136
let name = cx.tcx.item_name(did);
137137
Path {
138138
res: Res::Def(def_kind, did),
139-
segments: vec![PathSegment {
139+
segments: thin_vec![PathSegment {
140140
name,
141141
args: external_generic_args(cx, did, has_self, bindings, substs),
142142
}],

src/librustdoc/json/conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl FromWithTcx<clean::Type> for Type {
485485
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
486486
Tuple(t) => Type::Tuple(t.into_tcx(tcx)),
487487
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
488-
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s },
488+
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s.to_string() },
489489
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
490490
Infer => Type::Infer,
491491
RawPointer(mutability, type_) => Type::RawPointer {

0 commit comments

Comments
 (0)