Replace orx-concurrent-vec with append-only-vec

This commit is contained in:
Micha Reiser 2024-08-05 08:23:44 +02:00
parent 7bdf51cde2
commit 4a29bc5374
No known key found for this signature in database
3 changed files with 16 additions and 22 deletions

View file

@ -14,7 +14,7 @@ crossbeam = "0.8"
dashmap = "6"
hashlink = "0.9"
indexmap = "2"
orx-concurrent-vec = "2"
append-only-vec = "0.1"
tracing = "0.1"
parking_lot = "0.12"
rustc-hash = "2"

View file

@ -1,12 +1,10 @@
use crate::Database;
use append_only_vec::AppendOnlyVec;
use std::{
any::{Any, TypeId},
sync::Arc,
};
use orx_concurrent_vec::ConcurrentVec;
use crate::Database;
/// A `Views` struct is associated with some specific database type
/// (a `DatabaseImpl<U>` for some existential `U`). It contains functions
/// to downcast from that type to `dyn DbView` for various traits `DbView`.
@ -26,7 +24,7 @@ use crate::Database;
#[derive(Clone)]
pub struct Views {
source_type_id: TypeId,
view_casters: Arc<ConcurrentVec<ViewCaster>>,
view_casters: Arc<AppendOnlyVec<ViewCaster>>,
}
/// A ViewCaster contains a trait object that can cast from the
@ -91,7 +89,7 @@ impl Views {
let source_type_id = TypeId::of::<Db>();
Self {
source_type_id,
view_casters: Default::default(),
view_casters: Arc::new(AppendOnlyVec::new()),
}
}

View file

@ -1,11 +1,10 @@
use append_only_vec::AppendOnlyVec;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use std::any::{Any, TypeId};
use std::marker::PhantomData;
use std::thread::ThreadId;
use orx_concurrent_vec::ConcurrentVec;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use crate::cycle::CycleRecoveryStrategy;
use crate::ingredient::{Ingredient, Jar};
use crate::nonce::{Nonce, NonceGenerator};
@ -102,10 +101,10 @@ pub struct Zalsa {
/// Vector of ingredients.
///
/// Immutable unless the mutex on `ingredients_map` is held.
ingredients_vec: ConcurrentVec<Box<dyn Ingredient>>,
ingredients_vec: AppendOnlyVec<Box<dyn Ingredient>>,
/// Indices of ingredients that require reset when a new revision starts.
ingredients_requiring_reset: ConcurrentVec<IngredientIndex>,
ingredients_requiring_reset: AppendOnlyVec<IngredientIndex>,
/// The runtime for this particular salsa database handle.
/// Each handle gets its own runtime, but the runtimes have shared state between them.
@ -118,8 +117,8 @@ impl Zalsa {
views_of: Views::new::<Db>(),
nonce: NONCE.nonce(),
jar_map: Default::default(),
ingredients_vec: Default::default(),
ingredients_requiring_reset: Default::default(),
ingredients_vec: AppendOnlyVec::new(),
ingredients_requiring_reset: AppendOnlyVec::new(),
runtime: Runtime::default(),
}
}
@ -156,7 +155,7 @@ impl Zalsa {
expected_index.as_usize(),
actual_index,
"ingredient `{:?}` was predicted to have index `{:?}` but actually has index `{:?}`",
self.ingredients_vec.get(actual_index).unwrap(),
self.ingredients_vec[actual_index],
expected_index,
actual_index,
);
@ -168,12 +167,12 @@ impl Zalsa {
}
pub(crate) fn lookup_ingredient(&self, index: IngredientIndex) -> &dyn Ingredient {
&**self.ingredients_vec.get(index.as_usize()).unwrap()
&**(&self.ingredients_vec[index.as_usize()])
}
/// **NOT SEMVER STABLE**
pub fn lookup_ingredient_mut(&mut self, index: IngredientIndex) -> &mut dyn Ingredient {
&mut **self.ingredients_vec.get_mut(index.as_usize()).unwrap()
&mut **(&mut self.ingredients_vec[index.as_usize()])
}
/// **NOT SEMVER STABLE**
@ -204,10 +203,7 @@ impl Zalsa {
let new_revision = self.runtime.new_revision();
for index in self.ingredients_requiring_reset.iter() {
self.ingredients_vec
.get_mut(index.as_usize())
.unwrap()
.reset_for_new_revision();
self.ingredients_vec[index.as_usize()].reset_for_new_revision();
}
new_revision