From af75d2a451f6275d2ac4d4184f02ce49d0dd441b Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 28 Sep 2023 01:30:26 -0400 Subject: [PATCH] refactor(core): remove dashmap --- Cargo.lock | 14 -------------- Cargo.toml | 1 - src/core/scenegraph.rs | 15 ++++++--------- src/nodes/mod.rs | 16 ++++++++-------- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 737fc06..32a5940 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -530,19 +530,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.0", - "lock_api", - "once_cell", - "parking_lot_core 0.9.8", -] - [[package]] name = "directories" version = "5.0.1" @@ -2086,7 +2073,6 @@ dependencies = [ "clap", "color-eyre", "console-subscriber", - "dashmap", "directories", "glam 0.23.0", "global_counter", diff --git a/Cargo.toml b/Cargo.toml index 09d881b..b0454bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ lto = true [dependencies] color-eyre = { version = "0.6.2", default-features = false } clap = { version = "4.2.4", features = ["derive"] } -dashmap = "5.4.0" glam = { version = "0.23.0", features = ["mint"] } lazy_static = "1.4.0" mint = "0.5.9" diff --git a/src/core/scenegraph.rs b/src/core/scenegraph.rs index 230a99c..8f161b7 100644 --- a/src/core/scenegraph.rs +++ b/src/core/scenegraph.rs @@ -2,6 +2,8 @@ use crate::nodes::Node; use crate::{core::client::Client, nodes::Message}; use color_eyre::eyre::Result; use once_cell::sync::OnceCell; +use parking_lot::Mutex; +use rustc_hash::FxHashMap; use stardust_xr::scenegraph; use stardust_xr::scenegraph::ScenegraphError; use std::os::fd::OwnedFd; @@ -9,14 +11,10 @@ use std::sync::{Arc, Weak}; use tokio::sync::oneshot; use tracing::{debug, debug_span, instrument}; -use core::hash::BuildHasherDefault; -use dashmap::DashMap; -use rustc_hash::FxHasher; - #[derive(Default)] pub struct Scenegraph { pub(super) client: OnceCell>, - nodes: DashMap, BuildHasherDefault>, + nodes: Mutex>>, } impl Scenegraph { @@ -32,12 +30,12 @@ impl Scenegraph { pub fn add_node_raw(&self, node: Arc) { debug!(node = ?&*node, "Add node"); let path = node.get_path().to_string(); - self.nodes.insert(path, node); + self.nodes.lock().insert(path, node); } #[instrument(level = "debug", skip(self))] pub fn get_node(&self, path: &str) -> Option> { - let mut node = self.nodes.get(path)?.clone(); + let mut node = self.nodes.lock().get(path)?.clone(); while let Some(alias) = node.alias.get() { node = alias.original.upgrade()?; } @@ -46,8 +44,7 @@ impl Scenegraph { pub fn remove_node(&self, path: &str) -> Option> { debug!(path, "Remove node"); - let (_, node) = self.nodes.remove(path)?; - Some(node) + self.nodes.lock().remove(path) } } diff --git a/src/nodes/mod.rs b/src/nodes/mod.rs index fb0906c..ebe66bc 100644 --- a/src/nodes/mod.rs +++ b/src/nodes/mod.rs @@ -11,13 +11,11 @@ pub mod spatial; pub mod startup; use color_eyre::eyre::{eyre, Result}; -use core::hash::BuildHasherDefault; -use dashmap::DashMap; use nanoid::nanoid; use once_cell::sync::OnceCell; use parking_lot::Mutex; use portable_atomic::{AtomicBool, Ordering}; -use rustc_hash::FxHasher; +use rustc_hash::FxHashMap; use stardust_xr::messenger::MessageSenderHandle; use stardust_xr::scenegraph::ScenegraphError; use stardust_xr::schemas::flex::deserialize; @@ -70,8 +68,8 @@ pub struct Node { client: Weak, message_sender_handle: Option, // trailing_slash_pos: usize, - local_signals: DashMap>, - local_methods: DashMap>, + local_signals: Mutex>, + local_methods: Mutex>, destroyable: bool, pub alias: OnceCell>, @@ -198,10 +196,10 @@ impl Node { } pub fn add_local_signal(&self, name: &str, signal: Signal) { - self.local_signals.insert(name.to_string(), signal); + self.local_signals.lock().insert(name.to_string(), signal); } pub fn add_local_method(&self, name: &str, method: Method) { - self.local_methods.insert(name.to_string(), method); + self.local_methods.lock().insert(name.to_string(), method); } pub fn get_aspect( @@ -236,7 +234,9 @@ impl Node { } else { let signal = self .local_signals + .lock() .get(method) + .cloned() .ok_or(ScenegraphError::SignalNotFound)?; signal(self, calling_client, message).map_err(|error| ScenegraphError::SignalError { error: error.to_string(), @@ -269,7 +269,7 @@ impl Node { response, ) } else { - let Some(method) = self.local_methods.get(method) else { + let Some(method) = self.local_methods.lock().get(method).cloned() else { response.send(Err(ScenegraphError::MethodNotFound)); return; };