diff options
Diffstat (limited to 'crates/ra_hir/src/util.rs')
-rw-r--r-- | crates/ra_hir/src/util.rs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/crates/ra_hir/src/util.rs b/crates/ra_hir/src/util.rs index 46f423c91..0095ee45d 100644 --- a/crates/ra_hir/src/util.rs +++ b/crates/ra_hir/src/util.rs | |||
@@ -4,16 +4,9 @@ use std::sync::Arc; | |||
4 | 4 | ||
5 | /// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices). | 5 | /// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices). |
6 | /// The underlying values are cloned if there are other strong references. | 6 | /// The underlying values are cloned if there are other strong references. |
7 | pub(crate) fn make_mut_arc_slice<T: Clone, R>( | 7 | pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] { |
8 | a: &mut Arc<[T]>, | 8 | if Arc::get_mut(a).is_none() { |
9 | f: impl FnOnce(&mut [T]) -> R, | 9 | *a = a.iter().cloned().collect(); |
10 | ) -> R { | ||
11 | if let Some(s) = Arc::get_mut(a) { | ||
12 | f(s) | ||
13 | } else { | ||
14 | let mut v = a.to_vec(); | ||
15 | let r = f(&mut v); | ||
16 | *a = Arc::from(v); | ||
17 | r | ||
18 | } | 10 | } |
11 | Arc::get_mut(a).unwrap() | ||
19 | } | 12 | } |