From 0cef1e5fe15ea4fae28b343ce2241cfee5f105e2 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Mon, 25 Mar 2024 18:38:25 +0800 Subject: [PATCH] Simplify the implementation with a plain HashMap --- .../zenoh-shm/src/api/client_storage/mod.rs | 4 +-- commons/zenoh-shm/src/reader.rs | 29 +------------------ 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/commons/zenoh-shm/src/api/client_storage/mod.rs b/commons/zenoh-shm/src/api/client_storage/mod.rs index d468609bde..679197e246 100644 --- a/commons/zenoh-shm/src/api/client_storage/mod.rs +++ b/commons/zenoh-shm/src/api/client_storage/mod.rs @@ -135,12 +135,12 @@ impl SharedMemoryClientStorage { /// Get the list of supported SHM protocols. #[zenoh_macros::unstable_doc] pub fn supported_protocols(&self) -> Vec { - self.clients.get_clients().keys().copied().collect() + self.clients.keys().copied().collect() } fn new(clients: HashMap>) -> Self { Self { - clients: ClientStorage::new(clients), + clients: ClientStorage::from(clients), segments: RwLock::default(), } } diff --git a/commons/zenoh-shm/src/reader.rs b/commons/zenoh-shm/src/reader.rs index c2ce2303a9..25d53da43d 100644 --- a/commons/zenoh-shm/src/reader.rs +++ b/commons/zenoh-shm/src/reader.rs @@ -85,7 +85,6 @@ impl SharedMemoryReader { // find appropriate client let client = self .clients - .get_clients() .get(&id.protocol) .ok_or_else(|| zerror!("Unsupported SHM protocol: {}", id.protocol))?; @@ -106,33 +105,7 @@ impl SharedMemoryReader { } } -#[derive(Debug)] -pub(crate) struct ClientStorage -where - Inner: Sized, -{ - clients: HashMap, -} - -impl ClientStorage { - pub(crate) fn new(clients: HashMap) -> Self { - Self { clients } - } - - pub(crate) fn get_clients(&self) -> &HashMap { - &self.clients - } -} - -/// # Safety -/// Only immutable access to internal container is allowed, -/// so we are Send if the contained type is Send -unsafe impl Send for ClientStorage {} - -/// # Safety -/// Only immutable access to internal container is allowed, -/// so we are Sync if the contained type is Sync -unsafe impl Sync for ClientStorage {} +pub(crate) type ClientStorage = HashMap; #[derive(Debug, PartialEq, Eq, Hash)] pub(crate) struct GlobalDataSegmentID {