Skip to content

Commit 8b461d0

Browse files
authoredOct 29, 2023
Rollup merge of #117337 - camelid:genparamdefkind-thinvec, r=GuillaumeGomez
rustdoc: Use `ThinVec` in `GenericParamDefKind` This should hopefully reduce memory usage and improve performance since these vectors are often empty (and `GenericParamDefKind` is constructed *a lot*).
2 parents 7201240 + 3784adc commit 8b461d0

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed
 

‎src/librustdoc/clean/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn clean_generic_param_def<'tcx>(
498498
) -> GenericParamDef {
499499
let (name, kind) = match def.kind {
500500
ty::GenericParamDefKind::Lifetime => {
501-
(def.name, GenericParamDefKind::Lifetime { outlives: vec![] })
501+
(def.name, GenericParamDefKind::Lifetime { outlives: ThinVec::new() })
502502
}
503503
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
504504
let default = if has_default {
@@ -515,7 +515,7 @@ fn clean_generic_param_def<'tcx>(
515515
def.name,
516516
GenericParamDefKind::Type {
517517
did: def.def_id,
518-
bounds: vec![], // These are filled in from the where-clauses.
518+
bounds: ThinVec::new(), // These are filled in from the where-clauses.
519519
default: default.map(Box::new),
520520
synthetic,
521521
},
@@ -567,7 +567,7 @@ fn clean_generic_param<'tcx>(
567567
})
568568
.collect()
569569
} else {
570-
Vec::new()
570+
ThinVec::new()
571571
};
572572
(param.name.ident().name, GenericParamDefKind::Lifetime { outlives })
573573
}
@@ -580,7 +580,7 @@ fn clean_generic_param<'tcx>(
580580
.filter_map(|x| clean_generic_bound(x, cx))
581581
.collect()
582582
} else {
583-
Vec::new()
583+
ThinVec::new()
584584
};
585585
(
586586
param.name.ident().name,
@@ -636,7 +636,7 @@ pub(crate) fn clean_generics<'tcx>(
636636
match param.kind {
637637
GenericParamDefKind::Lifetime { .. } => unreachable!(),
638638
GenericParamDefKind::Type { did, ref bounds, .. } => {
639-
cx.impl_trait_bounds.insert(did.into(), bounds.clone());
639+
cx.impl_trait_bounds.insert(did.into(), bounds.to_vec());
640640
}
641641
GenericParamDefKind::Const { .. } => unreachable!(),
642642
}
@@ -3146,7 +3146,7 @@ fn clean_bound_vars<'tcx>(
31463146
name,
31473147
kind: GenericParamDefKind::Type {
31483148
did,
3149-
bounds: Vec::new(),
3149+
bounds: ThinVec::new(),
31503150
default: None,
31513151
synthetic: false,
31523152
},

‎src/librustdoc/clean/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub(crate) fn move_bounds_to_generic_parameters(generics: &mut clean::Generics)
145145
..
146146
}) = generics.params.iter_mut().find(|param| &param.name == arg)
147147
{
148-
param_bounds.append(bounds);
148+
param_bounds.extend(bounds.drain(..));
149149
} else if let WherePredicate::RegionPredicate { lifetime: Lifetime(arg), bounds } = &mut pred
150150
&& let Some(GenericParamDef {
151151
kind: GenericParamDefKind::Lifetime { outlives: param_bounds },

‎src/librustdoc/clean/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,8 @@ impl WherePredicate {
13251325

13261326
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
13271327
pub(crate) enum GenericParamDefKind {
1328-
Lifetime { outlives: Vec<Lifetime> },
1329-
Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
1328+
Lifetime { outlives: ThinVec<Lifetime> },
1329+
Type { did: DefId, bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
13301330
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
13311331
}
13321332

@@ -1344,7 +1344,7 @@ pub(crate) struct GenericParamDef {
13441344

13451345
impl GenericParamDef {
13461346
pub(crate) fn lifetime(name: Symbol) -> Self {
1347-
Self { name, kind: GenericParamDefKind::Lifetime { outlives: Vec::new() } }
1347+
Self { name, kind: GenericParamDefKind::Lifetime { outlives: ThinVec::new() } }
13481348
}
13491349

13501350
pub(crate) fn is_synthetic_param(&self) -> bool {
@@ -2521,7 +2521,7 @@ mod size_asserts {
25212521
static_assert_size!(DocFragment, 32);
25222522
static_assert_size!(GenericArg, 32);
25232523
static_assert_size!(GenericArgs, 32);
2524-
static_assert_size!(GenericParamDef, 56);
2524+
static_assert_size!(GenericParamDef, 40);
25252525
static_assert_size!(Generics, 16);
25262526
static_assert_size!(Item, 56);
25272527
static_assert_size!(ItemKind, 56);

0 commit comments

Comments
 (0)
Please sign in to comment.