From 8ebb8d29e18d7cb18bd2b57b004dcecd65a96232 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 24 May 2021 15:13:23 +0200 Subject: internal: intern `TypeBound`s Doesn't save much memory (~2 mb), but interning things is generally a good pattern to follow --- crates/hir_def/src/path/lower.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/hir_def/src/path') diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index a873325b2..cf4e7c02e 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs @@ -171,7 +171,9 @@ pub(super) fn lower_generic_args( let name = name_ref.as_name(); let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { - l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() + l.bounds() + .map(|it| Interned::new(TypeBound::from_ast(lower_ctx, it))) + .collect() } else { Vec::new() }; -- cgit v1.2.3 From 533e9207d39c27dc22de2645fc65891189a71739 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 24 May 2021 15:35:46 +0200 Subject: Intern `GenericArgs` This shaves off another ~4 mb or so --- crates/hir_def/src/path/lower.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/hir_def/src/path') diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index cf4e7c02e..5d5dd9c8f 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs @@ -3,7 +3,6 @@ mod lower_use; use crate::intern::Interned; -use std::sync::Arc; use either::Either; use hir_expand::name::{name, AsName}; @@ -48,7 +47,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { segment.ret_type(), ) }) - .map(Arc::new); + .map(Interned::new); segments.push(name); generic_args.push(args) } @@ -87,13 +86,13 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { // Insert the type reference (T in the above example) as Self parameter for the trait let last_segment = generic_args.iter_mut().rev().nth(num_segments.saturating_sub(1))?; - if last_segment.is_none() { - *last_segment = Some(Arc::new(GenericArgs::empty())); + let mut args_inner = match last_segment { + Some(it) => it.as_ref().clone(), + None => GenericArgs::empty(), }; - let args = last_segment.as_mut().unwrap(); - let mut args_inner = Arc::make_mut(args); args_inner.has_self_type = true; args_inner.args.insert(0, GenericArg::Type(self_type)); + *last_segment = Some(Interned::new(args_inner)); } } } -- cgit v1.2.3