aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/util.rs
diff options
context:
space:
mode:
authorShotaro Yamada <[email protected]>2019-10-14 11:50:12 +0100
committerShotaro Yamada <[email protected]>2019-10-14 11:50:12 +0100
commit3a55b5bf01ddc581a3f00fa56db725db93a131c6 (patch)
treeb3cbc2d477141507f76f5f973daa9fb5545bd731 /crates/ra_hir/src/util.rs
parentb462eb96b867cd38c60fb3d94ffd7688cec70f21 (diff)
make_mut_slice
Diffstat (limited to 'crates/ra_hir/src/util.rs')
-rw-r--r--crates/ra_hir/src/util.rs15
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.
7pub(crate) fn make_mut_arc_slice<T: Clone, R>( 7pub(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}