Skip to content

Commit b387180

Browse files
authored
Rollup merge of #114283 - oli-obk:parkin_lot_rwlock, r=SparrowLii
Use parking lot's rwlock even without parallel-rustc Considering that this doesn't affect perf, I think we should use the simplest solution.
2 parents 52bfceb + 3eb5733 commit b387180

File tree

1 file changed

+7
-21
lines changed
  • compiler/rustc_data_structures/src/sync

1 file changed

+7
-21
lines changed

compiler/rustc_data_structures/src/sync/vec.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,23 @@ impl<I: Idx, T: Copy> AppendOnlyIndexVec<I, T> {
4343

4444
#[derive(Default)]
4545
pub struct AppendOnlyVec<T: Copy> {
46-
#[cfg(not(parallel_compiler))]
47-
vec: elsa::vec::FrozenVec<T>,
48-
#[cfg(parallel_compiler)]
49-
vec: elsa::sync::LockFreeFrozenVec<T>,
46+
vec: parking_lot::RwLock<Vec<T>>,
5047
}
5148

5249
impl<T: Copy> AppendOnlyVec<T> {
5350
pub fn new() -> Self {
54-
Self {
55-
#[cfg(not(parallel_compiler))]
56-
vec: elsa::vec::FrozenVec::new(),
57-
#[cfg(parallel_compiler)]
58-
vec: elsa::sync::LockFreeFrozenVec::new(),
59-
}
51+
Self { vec: Default::default() }
6052
}
6153

6254
pub fn push(&self, val: T) -> usize {
63-
#[cfg(not(parallel_compiler))]
64-
let i = self.vec.len();
65-
#[cfg(not(parallel_compiler))]
66-
self.vec.push(val);
67-
#[cfg(parallel_compiler)]
68-
let i = self.vec.push(val);
69-
i
55+
let mut v = self.vec.write();
56+
let n = v.len();
57+
v.push(val);
58+
n
7059
}
7160

7261
pub fn get(&self, i: usize) -> Option<T> {
73-
#[cfg(not(parallel_compiler))]
74-
return self.vec.get_copy(i);
75-
#[cfg(parallel_compiler)]
76-
return self.vec.get(i);
62+
self.vec.read().get(i).copied()
7763
}
7864

7965
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> + '_ {

0 commit comments

Comments
 (0)