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*).
This commit is contained in:
parent
2cad938a81
commit
3784adcd64
@ -498,7 +498,7 @@ fn clean_generic_param_def<'tcx>(
|
|||||||
) -> GenericParamDef {
|
) -> GenericParamDef {
|
||||||
let (name, kind) = match def.kind {
|
let (name, kind) = match def.kind {
|
||||||
ty::GenericParamDefKind::Lifetime => {
|
ty::GenericParamDefKind::Lifetime => {
|
||||||
(def.name, GenericParamDefKind::Lifetime { outlives: vec![] })
|
(def.name, GenericParamDefKind::Lifetime { outlives: ThinVec::new() })
|
||||||
}
|
}
|
||||||
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
|
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
|
||||||
let default = if has_default {
|
let default = if has_default {
|
||||||
@ -515,7 +515,7 @@ fn clean_generic_param_def<'tcx>(
|
|||||||
def.name,
|
def.name,
|
||||||
GenericParamDefKind::Type {
|
GenericParamDefKind::Type {
|
||||||
did: def.def_id,
|
did: def.def_id,
|
||||||
bounds: vec![], // These are filled in from the where-clauses.
|
bounds: ThinVec::new(), // These are filled in from the where-clauses.
|
||||||
default: default.map(Box::new),
|
default: default.map(Box::new),
|
||||||
synthetic,
|
synthetic,
|
||||||
},
|
},
|
||||||
@ -567,7 +567,7 @@ fn clean_generic_param<'tcx>(
|
|||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
ThinVec::new()
|
||||||
};
|
};
|
||||||
(param.name.ident().name, GenericParamDefKind::Lifetime { outlives })
|
(param.name.ident().name, GenericParamDefKind::Lifetime { outlives })
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ fn clean_generic_param<'tcx>(
|
|||||||
.filter_map(|x| clean_generic_bound(x, cx))
|
.filter_map(|x| clean_generic_bound(x, cx))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
ThinVec::new()
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
param.name.ident().name,
|
param.name.ident().name,
|
||||||
@ -636,7 +636,7 @@ pub(crate) fn clean_generics<'tcx>(
|
|||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamDefKind::Lifetime { .. } => unreachable!(),
|
GenericParamDefKind::Lifetime { .. } => unreachable!(),
|
||||||
GenericParamDefKind::Type { did, ref bounds, .. } => {
|
GenericParamDefKind::Type { did, ref bounds, .. } => {
|
||||||
cx.impl_trait_bounds.insert(did.into(), bounds.clone());
|
cx.impl_trait_bounds.insert(did.into(), bounds.to_vec());
|
||||||
}
|
}
|
||||||
GenericParamDefKind::Const { .. } => unreachable!(),
|
GenericParamDefKind::Const { .. } => unreachable!(),
|
||||||
}
|
}
|
||||||
@ -3146,7 +3146,7 @@ fn clean_bound_vars<'tcx>(
|
|||||||
name,
|
name,
|
||||||
kind: GenericParamDefKind::Type {
|
kind: GenericParamDefKind::Type {
|
||||||
did,
|
did,
|
||||||
bounds: Vec::new(),
|
bounds: ThinVec::new(),
|
||||||
default: None,
|
default: None,
|
||||||
synthetic: false,
|
synthetic: false,
|
||||||
},
|
},
|
||||||
|
@ -145,7 +145,7 @@ pub(crate) fn move_bounds_to_generic_parameters(generics: &mut clean::Generics)
|
|||||||
..
|
..
|
||||||
}) = generics.params.iter_mut().find(|param| ¶m.name == arg)
|
}) = generics.params.iter_mut().find(|param| ¶m.name == arg)
|
||||||
{
|
{
|
||||||
param_bounds.append(bounds);
|
param_bounds.extend(bounds.drain(..));
|
||||||
} else if let WherePredicate::RegionPredicate { lifetime: Lifetime(arg), bounds } = &mut pred
|
} else if let WherePredicate::RegionPredicate { lifetime: Lifetime(arg), bounds } = &mut pred
|
||||||
&& let Some(GenericParamDef {
|
&& let Some(GenericParamDef {
|
||||||
kind: GenericParamDefKind::Lifetime { outlives: param_bounds },
|
kind: GenericParamDefKind::Lifetime { outlives: param_bounds },
|
||||||
|
@ -1325,8 +1325,8 @@ pub(crate) fn get_bounds(&self) -> Option<&[GenericBound]> {
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub(crate) enum GenericParamDefKind {
|
pub(crate) enum GenericParamDefKind {
|
||||||
Lifetime { outlives: Vec<Lifetime> },
|
Lifetime { outlives: ThinVec<Lifetime> },
|
||||||
Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
|
Type { did: DefId, bounds: ThinVec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
|
||||||
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
|
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1344,7 +1344,7 @@ pub(crate) struct GenericParamDef {
|
|||||||
|
|
||||||
impl GenericParamDef {
|
impl GenericParamDef {
|
||||||
pub(crate) fn lifetime(name: Symbol) -> Self {
|
pub(crate) fn lifetime(name: Symbol) -> Self {
|
||||||
Self { name, kind: GenericParamDefKind::Lifetime { outlives: Vec::new() } }
|
Self { name, kind: GenericParamDefKind::Lifetime { outlives: ThinVec::new() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_synthetic_param(&self) -> bool {
|
pub(crate) fn is_synthetic_param(&self) -> bool {
|
||||||
@ -2521,7 +2521,7 @@ mod size_asserts {
|
|||||||
static_assert_size!(DocFragment, 32);
|
static_assert_size!(DocFragment, 32);
|
||||||
static_assert_size!(GenericArg, 32);
|
static_assert_size!(GenericArg, 32);
|
||||||
static_assert_size!(GenericArgs, 32);
|
static_assert_size!(GenericArgs, 32);
|
||||||
static_assert_size!(GenericParamDef, 56);
|
static_assert_size!(GenericParamDef, 40);
|
||||||
static_assert_size!(Generics, 16);
|
static_assert_size!(Generics, 16);
|
||||||
static_assert_size!(Item, 56);
|
static_assert_size!(Item, 56);
|
||||||
static_assert_size!(ItemKind, 56);
|
static_assert_size!(ItemKind, 56);
|
||||||
|
Loading…
Reference in New Issue
Block a user