From daee746771f12f58f707787e8075d9f89ec0511d Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 14 Mar 2023 11:51:00 +0000 Subject: Add a usize-indexed append-only-vec --- compiler/rustc_data_structures/src/sync/vec.rs | 36 ++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_data_structures/src/sync') 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 { +pub struct AppendOnlyIndexVec { #[cfg(not(parallel_compiler))] vec: elsa::vec::FrozenVec, #[cfg(parallel_compiler)] @@ -10,7 +10,7 @@ pub struct AppendOnlyVec { _marker: PhantomData, } -impl AppendOnlyVec { +impl AppendOnlyIndexVec { pub fn new() -> Self { Self { #[cfg(not(parallel_compiler))] @@ -39,3 +39,35 @@ impl AppendOnlyVec { return self.vec.get(i); } } + +pub struct AppendOnlyVec { + #[cfg(not(parallel_compiler))] + vec: elsa::vec::FrozenVec, + #[cfg(parallel_compiler)] + vec: elsa::sync::LockFreeFrozenVec, +} + +impl AppendOnlyVec { + 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 { + #[cfg(not(parallel_compiler))] + return self.vec.get_copy(i); + #[cfg(parallel_compiler)] + return self.vec.get(i); + } +} -- cgit 1.4.1-3-g733a5