diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-14 14:14:18 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-14 14:14:18 +0100 |
commit | e182825170e346abb84240b84458b49b73783dca (patch) | |
tree | 899e18326f89571f835a0d9eb2f42a71f714f2df /crates/ra_hir/src/ty/infer | |
parent | 1f4fbc0035a6a9ee1b599a3aa9f236989633a9f7 (diff) | |
parent | 3a55b5bf01ddc581a3f00fa56db725db93a131c6 (diff) |
Merge #2006
2006: Improvements around `Arc<[T]>` r=matklad a=sinkuu
First commit tries to avoid cloning `Arc<[T]>` to a temporary `Vec` for mutating it, if there are no other strong references. Second commit utilizes [`FromIterator for Arc<[T]>`](https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-FromIterator%3CT%3E) instead of `.collect::<Vec<_>>().into()` to avoid allocation in `From<Vec<T>> for Arc<[T]>`.
Co-authored-by: Shotaro Yamada <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/unify.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs index d161aa6b3..014c7981f 100644 --- a/crates/ra_hir/src/ty/infer/unify.rs +++ b/crates/ra_hir/src/ty/infer/unify.rs | |||
@@ -6,6 +6,7 @@ use crate::ty::{ | |||
6 | Canonical, InEnvironment, InferTy, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, | 6 | Canonical, InEnvironment, InferTy, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, |
7 | TypeWalk, | 7 | TypeWalk, |
8 | }; | 8 | }; |
9 | use crate::util::make_mut_slice; | ||
9 | 10 | ||
10 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 11 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
11 | pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> | 12 | pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> |
@@ -74,10 +75,11 @@ where | |||
74 | }) | 75 | }) |
75 | } | 76 | } |
76 | 77 | ||
77 | fn do_canonicalize_trait_ref(&mut self, trait_ref: TraitRef) -> TraitRef { | 78 | fn do_canonicalize_trait_ref(&mut self, mut trait_ref: TraitRef) -> TraitRef { |
78 | let substs = | 79 | for ty in make_mut_slice(&mut trait_ref.substs.0) { |
79 | trait_ref.substs.iter().map(|ty| self.do_canonicalize_ty(ty.clone())).collect(); | 80 | *ty = self.do_canonicalize_ty(ty.clone()); |
80 | TraitRef { trait_: trait_ref.trait_, substs: Substs(substs) } | 81 | } |
82 | trait_ref | ||
81 | } | 83 | } |
82 | 84 | ||
83 | fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> { | 85 | fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> { |
@@ -87,10 +89,11 @@ where | |||
87 | } | 89 | } |
88 | } | 90 | } |
89 | 91 | ||
90 | fn do_canonicalize_projection_ty(&mut self, projection_ty: ProjectionTy) -> ProjectionTy { | 92 | fn do_canonicalize_projection_ty(&mut self, mut projection_ty: ProjectionTy) -> ProjectionTy { |
91 | let params = | 93 | for ty in make_mut_slice(&mut projection_ty.parameters.0) { |
92 | projection_ty.parameters.iter().map(|ty| self.do_canonicalize_ty(ty.clone())).collect(); | 94 | *ty = self.do_canonicalize_ty(ty.clone()); |
93 | ProjectionTy { associated_ty: projection_ty.associated_ty, parameters: Substs(params) } | 95 | } |
96 | projection_ty | ||
94 | } | 97 | } |
95 | 98 | ||
96 | fn do_canonicalize_projection_predicate( | 99 | fn do_canonicalize_projection_predicate( |