aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/util.rs
blob: 0095ee45d3c60fddf8a2db5f7892a4c219cc7e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
//! Internal utility functions.

use std::sync::Arc;

/// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices).
/// The underlying values are cloned if there are other strong references.
pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
    if Arc::get_mut(a).is_none() {
        *a = a.iter().cloned().collect();
    }
    Arc::get_mut(a).unwrap()
}