aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/display.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-08 17:25:18 +0100
committerFlorian Diebold <[email protected]>2021-04-08 21:48:47 +0100
commitbe03db0e3a75533f34d48c3014d532919b30a9e9 (patch)
tree3742a817b8238043a3a855d92532c7342815210e /crates/hir_ty/src/display.rs
parenta169fa6a832a513cd1534d1a6566e4584ca5fb6a (diff)
Intern Substitutions
(Costs a bit of performance, reduces memory usage on RA by ~10%.)
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r--crates/hir_ty/src/display.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index d7a3977e5..92224b46b 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -265,7 +265,7 @@ impl HirDisplay for ProjectionTy {
265 write!(f, " as {}", trait_.name)?; 265 write!(f, " as {}", trait_.name)?;
266 if self.substitution.len(&Interner) > 1 { 266 if self.substitution.len(&Interner) > 1 {
267 write!(f, "<")?; 267 write!(f, "<")?;
268 f.write_joined(&self.substitution.interned()[1..], ", ")?; 268 f.write_joined(&self.substitution.as_slice(&Interner)[1..], ", ")?;
269 write!(f, ">")?; 269 write!(f, ">")?;
270 } 270 }
271 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?; 271 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?;
@@ -416,7 +416,7 @@ impl HirDisplay for Ty {
416 write!(f, ",)")?; 416 write!(f, ",)")?;
417 } else { 417 } else {
418 write!(f, "(")?; 418 write!(f, "(")?;
419 f.write_joined(&*substs.interned(), ", ")?; 419 f.write_joined(&*substs.as_slice(&Interner), ", ")?;
420 write!(f, ")")?; 420 write!(f, ")")?;
421 } 421 }
422 } 422 }
@@ -444,7 +444,7 @@ impl HirDisplay for Ty {
444 // We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self? 444 // We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
445 if total_len > 0 { 445 if total_len > 0 {
446 write!(f, "<")?; 446 write!(f, "<")?;
447 f.write_joined(&parameters.interned()[..total_len], ", ")?; 447 f.write_joined(&parameters.as_slice(&Interner)[..total_len], ", ")?;
448 write!(f, ">")?; 448 write!(f, ">")?;
449 } 449 }
450 } 450 }
@@ -491,7 +491,7 @@ impl HirDisplay for Ty {
491 .map(|generic_def_id| f.db.generic_defaults(generic_def_id)) 491 .map(|generic_def_id| f.db.generic_defaults(generic_def_id))
492 .filter(|defaults| !defaults.is_empty()) 492 .filter(|defaults| !defaults.is_empty())
493 { 493 {
494 None => parameters.interned().as_ref(), 494 None => parameters.as_slice(&Interner),
495 Some(default_parameters) => { 495 Some(default_parameters) => {
496 let mut default_from = 0; 496 let mut default_from = 0;
497 for (i, parameter) in parameters.iter(&Interner).enumerate() { 497 for (i, parameter) in parameters.iter(&Interner).enumerate() {
@@ -515,11 +515,11 @@ impl HirDisplay for Ty {
515 } 515 }
516 } 516 }
517 } 517 }
518 &parameters.interned()[0..default_from] 518 &parameters.as_slice(&Interner)[0..default_from]
519 } 519 }
520 } 520 }
521 } else { 521 } else {
522 parameters.interned().as_ref() 522 parameters.as_slice(&Interner)
523 }; 523 };
524 if !parameters_to_write.is_empty() { 524 if !parameters_to_write.is_empty() {
525 write!(f, "<")?; 525 write!(f, "<")?;
@@ -542,7 +542,7 @@ impl HirDisplay for Ty {
542 write!(f, "{}::{}", trait_.name, type_alias_data.name)?; 542 write!(f, "{}::{}", trait_.name, type_alias_data.name)?;
543 if parameters.len(&Interner) > 0 { 543 if parameters.len(&Interner) > 0 {
544 write!(f, "<")?; 544 write!(f, "<")?;
545 f.write_joined(&*parameters.interned(), ", ")?; 545 f.write_joined(&*parameters.as_slice(&Interner), ", ")?;
546 write!(f, ">")?; 546 write!(f, ">")?;
547 } 547 }
548 } else { 548 } else {
@@ -749,13 +749,13 @@ fn write_bounds_like_dyn_trait(
749 // existential) here, which is the only thing that's 749 // existential) here, which is the only thing that's
750 // possible in actual Rust, and hence don't print it 750 // possible in actual Rust, and hence don't print it
751 write!(f, "{}", f.db.trait_data(trait_).name)?; 751 write!(f, "{}", f.db.trait_data(trait_).name)?;
752 if let [_, params @ ..] = &*trait_ref.substitution.interned().as_slice() { 752 if let [_, params @ ..] = &*trait_ref.substitution.as_slice(&Interner) {
753 if is_fn_trait { 753 if is_fn_trait {
754 if let Some(args) = 754 if let Some(args) =
755 params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple()) 755 params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple())
756 { 756 {
757 write!(f, "(")?; 757 write!(f, "(")?;
758 f.write_joined(&*args.interned(), ", ")?; 758 f.write_joined(args.as_slice(&Interner), ", ")?;
759 write!(f, ")")?; 759 write!(f, ")")?;
760 } 760 }
761 } else if !params.is_empty() { 761 } else if !params.is_empty() {
@@ -814,7 +814,7 @@ fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<()
814 write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?; 814 write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?;
815 if tr.substitution.len(&Interner) > 1 { 815 if tr.substitution.len(&Interner) > 1 {
816 write!(f, "<")?; 816 write!(f, "<")?;
817 f.write_joined(&tr.substitution.interned()[1..], ", ")?; 817 f.write_joined(&tr.substitution.as_slice(&Interner)[1..], ", ")?;
818 write!(f, ">")?; 818 write!(f, ">")?;
819 } 819 }
820 Ok(()) 820 Ok(())