mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Reuse empty GenericParams
This saves back 15mb that went for typeref source maps.
This commit is contained in:
parent
1fae57fa55
commit
39747cb518
2 changed files with 19 additions and 6 deletions
|
@ -3,7 +3,7 @@
|
||||||
//! generic parameters. See also the `Generics` type and the `generics_of` query
|
//! generic parameters. See also the `Generics` type and the `generics_of` query
|
||||||
//! in rustc.
|
//! in rustc.
|
||||||
|
|
||||||
use std::ops;
|
use std::{ops, sync::LazyLock};
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
|
@ -412,7 +412,7 @@ impl GenericParams {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let generics = generic_params.finish(types_map, &mut types_source_maps);
|
let generics = generic_params.finish(types_map, &mut types_source_maps);
|
||||||
(Arc::new(generics), Some(Arc::new(types_source_maps)))
|
(generics, Some(Arc::new(types_source_maps)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericDefId::AdtId(AdtId::StructId(id)) => id_to_generics(db, id, enabled_params),
|
GenericDefId::AdtId(AdtId::StructId(id)) => id_to_generics(db, id, enabled_params),
|
||||||
|
@ -686,19 +686,32 @@ impl GenericParamsCollector {
|
||||||
self,
|
self,
|
||||||
mut generics_types_map: TypesMap,
|
mut generics_types_map: TypesMap,
|
||||||
generics_types_source_map: &mut TypesSourceMap,
|
generics_types_source_map: &mut TypesSourceMap,
|
||||||
) -> GenericParams {
|
) -> Arc<GenericParams> {
|
||||||
let Self { mut lifetimes, mut type_or_consts, mut where_predicates } = self;
|
let Self { mut lifetimes, mut type_or_consts, mut where_predicates } = self;
|
||||||
|
|
||||||
|
if lifetimes.is_empty() && type_or_consts.is_empty() && where_predicates.is_empty() {
|
||||||
|
static EMPTY: LazyLock<Arc<GenericParams>> = LazyLock::new(|| {
|
||||||
|
Arc::new(GenericParams {
|
||||||
|
lifetimes: Arena::new(),
|
||||||
|
type_or_consts: Arena::new(),
|
||||||
|
where_predicates: Box::default(),
|
||||||
|
types_map: TypesMap::default(),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
return Arc::clone(&EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
lifetimes.shrink_to_fit();
|
lifetimes.shrink_to_fit();
|
||||||
type_or_consts.shrink_to_fit();
|
type_or_consts.shrink_to_fit();
|
||||||
where_predicates.shrink_to_fit();
|
where_predicates.shrink_to_fit();
|
||||||
generics_types_map.shrink_to_fit();
|
generics_types_map.shrink_to_fit();
|
||||||
generics_types_source_map.shrink_to_fit();
|
generics_types_source_map.shrink_to_fit();
|
||||||
GenericParams {
|
Arc::new(GenericParams {
|
||||||
type_or_consts,
|
type_or_consts,
|
||||||
lifetimes,
|
lifetimes,
|
||||||
where_predicates: where_predicates.into_boxed_slice(),
|
where_predicates: where_predicates.into_boxed_slice(),
|
||||||
types_map: generics_types_map,
|
types_map: generics_types_map,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -895,7 +895,7 @@ impl<'a> Ctx<'a> {
|
||||||
generics.fill(&body_ctx, node, add_param_attrs);
|
generics.fill(&body_ctx, node, add_param_attrs);
|
||||||
|
|
||||||
let generics = generics.finish(types_map, &mut types_source_map);
|
let generics = generics.finish(types_map, &mut types_source_map);
|
||||||
(Arc::new(generics), types_source_map)
|
(generics, types_source_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_type_bounds(
|
fn lower_type_bounds(
|
||||||
|
|
Loading…
Reference in a new issue