Skip to content

Commit

Permalink
improve: use rustc-hash instead of fxhash for more active support (#14)
Browse files Browse the repository at this point in the history
* improve: use rustc-hash instead of fxhash for more active support

* reduce unnecessary heap allocation
  • Loading branch information
Ggiggle authored Jan 25, 2024
1 parent 9354a39 commit b3aa605
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 49 deletions.
84 changes: 41 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metainfo"
version = "0.7.8"
version = "0.7.9"
authors = ["Volo Team <volo@cloudwego.io>"]
edition = "2021"
description = "Transmissing metainfo across components."
Expand All @@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
ahash = "0.8"
faststr = "0.2"
fxhash = "0.2"
rustc-hash = "1"
paste = "1"
tokio = { version = "1", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion src/faststr_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{any::TypeId, collections::hash_map::Entry};

use faststr::FastStr;
use fxhash::FxHashMap;
use rustc_hash::FxHashMap;

/// This is an optimized version of TypeMap to FastStr that eliminates the need to Box the values.
///
Expand Down
7 changes: 4 additions & 3 deletions src/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
marker::PhantomData,
};

use fxhash::FxHashMap;
use rustc_hash::FxHashMap;

pub(crate) type AnyObject = Box<dyn Any + Send + Sync>;

Expand All @@ -19,7 +19,7 @@ impl<'a, K, V> Entry<'a, K, V> {
where
V: Send + Sync + 'static,
{
let v = self.inner.or_insert(Box::new(default));
let v = self.inner.or_insert_with(|| Box::new(default));
v.downcast_mut().unwrap()
}

Expand Down Expand Up @@ -54,12 +54,13 @@ impl<'a, K, V> Entry<'a, K, V> {
}
}

#[allow(clippy::unwrap_or_default)]
#[inline]
pub fn or_default(self) -> &'a mut V
where
V: Default + Send + Sync + 'static,
{
self.or_insert(V::default())
self.or_insert_with(V::default)
}
}

Expand Down

0 comments on commit b3aa605

Please sign in to comment.