Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to rustc-hash 2 #17

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>"]
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
Loading