diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-03-14 11:51:00 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-04-04 09:01:44 +0000 |
| commit | daee746771f12f58f707787e8075d9f89ec0511d (patch) | |
| tree | 36789c0cb68a4d9021a1e124f38395e3f2bc563e /compiler/rustc_data_structures/src/sync | |
| parent | c7a3a943f2a1dd974f8887fe79ab3ff43f7005ac (diff) | |
| download | rust-daee746771f12f58f707787e8075d9f89ec0511d.tar.gz rust-daee746771f12f58f707787e8075d9f89ec0511d.zip | |
Add a usize-indexed append-only-vec
Diffstat (limited to 'compiler/rustc_data_structures/src/sync')
| -rw-r--r-- | compiler/rustc_data_structures/src/sync/vec.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/compiler/rustc_data_structures/src/sync/vec.rs b/compiler/rustc_data_structures/src/sync/vec.rs index cbea4f05999..6ffd2a75e81 100644 --- a/compiler/rustc_data_structures/src/sync/vec.rs +++ b/compiler/rustc_data_structures/src/sync/vec.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use rustc_index::vec::Idx; -pub struct AppendOnlyVec<I: Idx, T: Copy> { +pub struct AppendOnlyIndexVec<I: Idx, T: Copy> { #[cfg(not(parallel_compiler))] vec: elsa::vec::FrozenVec<T>, #[cfg(parallel_compiler)] @@ -10,7 +10,7 @@ pub struct AppendOnlyVec<I: Idx, T: Copy> { _marker: PhantomData<fn(&I)>, } -impl<I: Idx, T: Copy> AppendOnlyVec<I, T> { +impl<I: Idx, T: Copy> AppendOnlyIndexVec<I, T> { pub fn new() -> Self { Self { #[cfg(not(parallel_compiler))] @@ -39,3 +39,35 @@ impl<I: Idx, T: Copy> AppendOnlyVec<I, T> { return self.vec.get(i); } } + +pub struct AppendOnlyVec<T: Copy> { + #[cfg(not(parallel_compiler))] + vec: elsa::vec::FrozenVec<T>, + #[cfg(parallel_compiler)] + vec: elsa::sync::LockFreeFrozenVec<T>, +} + +impl<T: Copy> AppendOnlyVec<T> { + pub fn new() -> Self { + Self { + #[cfg(not(parallel_compiler))] + vec: elsa::vec::FrozenVec::new(), + #[cfg(parallel_compiler)] + vec: elsa::sync::LockFreeFrozenVec::new(), + } + } + + pub fn push(&self, val: T) { + #[cfg(not(parallel_compiler))] + self.vec.push(val); + #[cfg(parallel_compiler)] + self.vec.push(val) + } + + pub fn get(&self, i: usize) -> Option<T> { + #[cfg(not(parallel_compiler))] + return self.vec.get_copy(i); + #[cfg(parallel_compiler)] + return self.vec.get(i); + } +} |
