Skip to content

Commit

Permalink
feat: update to rustc-hash 2
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu committed Jun 24, 2024
1 parent ed502ea commit 7fcaf82
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 62 deletions.
140 changes: 88 additions & 52 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.11"
version = "0.7.12"
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"
rustc-hash = "1"
rustc-hash = { version = "2", features = ["rand"] }
paste = "1"
tokio = { version = "1", optional = true }

Expand Down
8 changes: 4 additions & 4 deletions src/faststr_map.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use std::{any::TypeId, collections::hash_map::Entry};

use faststr::FastStr;
use rustc_hash::FxHashMap;
use rustc_hash::FxHashMapRand;

/// This is an optimized version of TypeMap to FastStr that eliminates the need to Box the values.
///
/// This map is suitable for T that impls both From<FastStr> and Into<FastStr>.
#[derive(Debug, Default)]
pub struct FastStrMap {
inner: FxHashMap<TypeId, FastStr>,
inner: FxHashMapRand<TypeId, FastStr>,
}

impl FastStrMap {
#[inline]
pub fn new() -> Self {
Self {
inner: FxHashMap::default(),
inner: FxHashMapRand::default(),
}
}

#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Self {
inner: FxHashMap::with_capacity_and_hasher(capacity, Default::default()),
inner: FxHashMapRand::with_capacity_and_hasher(capacity, Default::default()),
}
}

Expand Down
8 changes: 4 additions & 4 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 rustc_hash::FxHashMap;
use rustc_hash::FxHashMapRand;

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

Expand Down Expand Up @@ -66,21 +66,21 @@ impl<'a, K, V> Entry<'a, K, V> {

#[derive(Debug, Default)]
pub struct TypeMap {
inner: FxHashMap<TypeId, AnyObject>,
inner: FxHashMapRand<TypeId, AnyObject>,
}

impl TypeMap {
#[inline]
pub fn new() -> Self {
TypeMap {
inner: FxHashMap::default(),
inner: FxHashMapRand::default(),
}
}

#[inline]
pub fn with_capacity(capacity: usize) -> Self {
TypeMap {
inner: FxHashMap::with_capacity_and_hasher(capacity, Default::default()),
inner: FxHashMapRand::with_capacity_and_hasher(capacity, Default::default()),
}
}

Expand Down

0 comments on commit 7fcaf82

Please sign in to comment.