aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
authorShotaro Yamada <[email protected]>2019-10-14 04:56:18 +0100
committerShotaro Yamada <[email protected]>2019-10-14 06:25:05 +0100
commitf8d4cdc170bead42db3ffa647318ecf2bd6430e7 (patch)
tree2c020016af1fd5239fdad65b816b4cccea97df41 /crates/ra_hir/src/ty.rs
parent77f2dd96a122e59a8d8df8afb53a741df9b1af76 (diff)
Avoid cloning `Arc<[T]>` into a vec if possible
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index d161735e8..fc4909d11 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -17,8 +17,8 @@ use std::sync::Arc;
17use std::{fmt, iter, mem}; 17use std::{fmt, iter, mem};
18 18
19use crate::{ 19use crate::{
20 db::HirDatabase, expr::ExprId, type_ref::Mutability, Adt, Crate, DefWithBody, GenericParams, 20 db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_arc_slice, Adt, Crate,
21 HasGenericParams, Name, Trait, TypeAlias, 21 DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias,
22}; 22};
23use display::{HirDisplay, HirFormatter}; 23use display::{HirDisplay, HirFormatter};
24 24
@@ -308,12 +308,11 @@ impl Substs {
308 } 308 }
309 309
310 pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { 310 pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
311 // Without an Arc::make_mut_slice, we can't avoid the clone here: 311 make_mut_arc_slice(&mut self.0, |s| {
312 let mut v: Vec<_> = self.0.iter().cloned().collect(); 312 for t in s {
313 for t in &mut v { 313 t.walk_mut(f);
314 t.walk_mut(f); 314 }
315 } 315 });
316 self.0 = v.into();
317 } 316 }
318 317
319 pub fn as_single(&self) -> &Ty { 318 pub fn as_single(&self) -> &Ty {
@@ -541,12 +540,11 @@ impl TypeWalk for FnSig {
541 } 540 }
542 541
543 fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { 542 fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
544 // Without an Arc::make_mut_slice, we can't avoid the clone here: 543 make_mut_arc_slice(&mut self.params_and_return, |s| {
545 let mut v: Vec<_> = self.params_and_return.iter().cloned().collect(); 544 for t in s {
546 for t in &mut v { 545 t.walk_mut(f);
547 t.walk_mut(f); 546 }
548 } 547 });
549 self.params_and_return = v.into();
550 } 548 }
551} 549}
552 550
@@ -756,11 +754,11 @@ impl TypeWalk for Ty {
756 p_ty.parameters.walk_mut(f); 754 p_ty.parameters.walk_mut(f);
757 } 755 }
758 Ty::Dyn(predicates) | Ty::Opaque(predicates) => { 756 Ty::Dyn(predicates) | Ty::Opaque(predicates) => {
759 let mut v: Vec<_> = predicates.iter().cloned().collect(); 757 make_mut_arc_slice(predicates, |s| {
760 for p in &mut v { 758 for p in s {
761 p.walk_mut(f); 759 p.walk_mut(f);
762 } 760 }
763 *predicates = v.into(); 761 });
764 } 762 }
765 Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {} 763 Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {}
766 } 764 }