From e2a11f297c03362ff6863203cccd2e1f5ebba323 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Tue, 18 Jun 2024 18:11:37 +0700 Subject: [PATCH] fix: docs and types --- .../runtime_extensions/hermes/sqlite/state.rs | 25 +++++++++++-------- wasm/integration-test/README.md | 4 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hermes/bin/src/runtime_extensions/hermes/sqlite/state.rs b/hermes/bin/src/runtime_extensions/hermes/sqlite/state.rs index 8d57109f0..5d22850e4 100644 --- a/hermes/bin/src/runtime_extensions/hermes/sqlite/state.rs +++ b/hermes/bin/src/runtime_extensions/hermes/sqlite/state.rs @@ -9,11 +9,14 @@ use once_cell::sync::Lazy; use crate::app::HermesAppName; +/// The object pointer used specifically with C objects like `sqlite3` or `sqlite3_stmt`. +type ObjectPointer = usize; + /// Represents an individual state for a particular object. #[derive(Debug)] -pub(crate) struct ResourceObjectState { +pub(crate) struct ResourceObjectState { /// A map holding key-value pairs of an object ID and a value. - id_map: HashMap, + id_map: HashMap, /// The current incremental state of ID. current_id: Option, } @@ -21,12 +24,12 @@ pub(crate) struct ResourceObjectState { /// Represents the state of resources. pub(crate) struct ResourceState { /// The state of database object. - db_state: ResourceObjectState, + db_state: ResourceObjectState, /// The state of database statement object. - stmt_state: ResourceObjectState, + stmt_state: ResourceObjectState, } -impl ResourceObjectState { +impl ResourceObjectState { /// Create a new `ResourceObjectState` with initial state. fn new() -> Self { Self { @@ -38,7 +41,7 @@ impl ResourceObjectState { /// Adds a value into the resource. If it does not exist, assigns one and returns the /// new created key ID. In case of the key ID is running out of numbers, returns /// `None`. - pub(super) fn add_object(&mut self, object_ptr: T) -> Option { + pub(super) fn add_object(&mut self, object_ptr: ObjectPointer) -> Option { if let Some((existing_id, _)) = self.id_map.iter().find(|(_, val)| val == &&object_ptr) { Some(*existing_id) } else { @@ -57,12 +60,12 @@ impl ResourceObjectState { } /// Retrieves a value according to its key ID. - pub(super) fn get_object_by_id(&self, id: u32) -> Option<::Owned> { + pub(super) fn get_object_by_id(&self, id: u32) -> Option { self.id_map.get(&id).map(ToOwned::to_owned) } /// Deletes a value according to its key ID, and returns the removed value if exists. - pub(super) fn delete_object_by_id(&mut self, id: u32) -> Option { + pub(super) fn delete_object_by_id(&mut self, id: u32) -> Option { self.id_map.remove(&id) } } @@ -77,12 +80,12 @@ impl ResourceState { } /// Gets the state for managing database objects. - pub(super) fn get_db_state(&mut self) -> &mut ResourceObjectState { + pub(super) fn get_db_state(&mut self) -> &mut ResourceObjectState { &mut self.db_state } /// Gets the state for managing statement objects. - pub(super) fn get_stmt_state(&mut self) -> &mut ResourceObjectState { + pub(super) fn get_stmt_state(&mut self) -> &mut ResourceObjectState { &mut self.stmt_state } } @@ -91,7 +94,7 @@ impl ResourceState { type State = DashMap; /// Global state to hold `SQLite` resources. -static SQLITE_INTERNAL_STATE: Lazy = Lazy::new(DashMap::new); +static SQLITE_INTERNAL_STATE: Lazy = Lazy::new(State::new); /// Represents the internal state object for `SQLite` module. pub(crate) struct InternalState; diff --git a/wasm/integration-test/README.md b/wasm/integration-test/README.md index 4f5acc38b..0be0431eb 100644 --- a/wasm/integration-test/README.md +++ b/wasm/integration-test/README.md @@ -25,7 +25,7 @@ You can visit `wasm/wasi/Earthfile` for supported languages needed to generate H ### SQLite benchmark result * Test: simple sequential insertion between persistent and in-memory database (100 iterations) - * Persistent: 8,493,667 ns/iter (+/- 0) - * In-memory: 37,492,916 ns/iter (+/- 0) + * Persistent: 37,492,916 ns/iter (+/- 0) + * In-memory: 8,493,667 ns/iter (+/- 0) Tested on MacBook Pro with M3 Pro chip 12-core CPU, 18-core GPU, and 18GB unified memory.