Use FxHash in uv-auth (#6149)
This commit is contained in:
Generated
+1
@@ -4553,6 +4553,7 @@ dependencies = [
|
||||
"reqwest",
|
||||
"reqwest-middleware",
|
||||
"rust-netrc",
|
||||
"rustc-hash 2.0.0",
|
||||
"tempfile",
|
||||
"test-log",
|
||||
"tokio",
|
||||
|
||||
@@ -15,12 +15,19 @@ use tokio::sync::Notify;
|
||||
///
|
||||
/// Note that this always clones the value out of the underlying map. Because
|
||||
/// of this, it's common to wrap the `V` in an `Arc<V>` to make cloning cheap.
|
||||
pub struct OnceMap<K, V, H = RandomState> {
|
||||
items: DashMap<K, Value<V>, H>,
|
||||
pub struct OnceMap<K, V, S = RandomState> {
|
||||
items: DashMap<K, Value<V>, S>,
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash, V: Clone, H: BuildHasher + Clone> OnceMap<K, V, H> {
|
||||
// Create a [`OnceMap`] with the specified capacity and hasher.
|
||||
/// Create a [`OnceMap`] with the specified hasher.
|
||||
pub fn with_hasher(hasher: H) -> OnceMap<K, V, H> {
|
||||
OnceMap {
|
||||
items: DashMap::with_hasher(hasher),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a [`OnceMap`] with the specified capacity and hasher.
|
||||
pub fn with_capacity_and_hasher(capacity: usize, hasher: H) -> OnceMap<K, V, H> {
|
||||
OnceMap {
|
||||
items: DashMap::with_capacity_and_hasher(capacity, hasher),
|
||||
|
||||
@@ -16,6 +16,7 @@ once-map = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
reqwest-middleware = { workspace = true }
|
||||
rust-netrc = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
url = { workspace = true }
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
use std::hash::BuildHasherDefault;
|
||||
use std::sync::Arc;
|
||||
use std::{collections::HashMap, sync::RwLock};
|
||||
use std::sync::RwLock;
|
||||
|
||||
use rustc_hash::{FxHashMap, FxHasher};
|
||||
use tracing::trace;
|
||||
use url::Url;
|
||||
|
||||
use once_map::OnceMap;
|
||||
|
||||
use crate::credentials::{Credentials, Username};
|
||||
use crate::Realm;
|
||||
|
||||
use once_map::OnceMap;
|
||||
use tracing::trace;
|
||||
use url::Url;
|
||||
type FxOnceMap<K, V> = OnceMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
|
||||
pub struct CredentialsCache {
|
||||
/// A cache per realm and username
|
||||
realms: RwLock<HashMap<(Realm, Username), Arc<Credentials>>>,
|
||||
realms: RwLock<FxHashMap<(Realm, Username), Arc<Credentials>>>,
|
||||
/// A cache tracking the result of fetches from external services
|
||||
pub(crate) fetches: OnceMap<(Realm, Username), Option<Arc<Credentials>>>,
|
||||
pub(crate) fetches: FxOnceMap<(Realm, Username), Option<Arc<Credentials>>>,
|
||||
/// A cache per URL, uses a trie for efficient prefix queries.
|
||||
urls: RwLock<UrlTrie>,
|
||||
}
|
||||
@@ -27,8 +32,8 @@ impl CredentialsCache {
|
||||
/// Create a new cache.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
fetches: OnceMap::default(),
|
||||
realms: RwLock::new(HashMap::new()),
|
||||
fetches: FxOnceMap::default(),
|
||||
realms: RwLock::new(FxHashMap::default()),
|
||||
urls: RwLock::new(UrlTrie::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,17 +25,6 @@ struct SharedInMemoryIndex {
|
||||
pub(crate) type FxOnceMap<K, V> = OnceMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
|
||||
impl InMemoryIndex {
|
||||
/// Create an `InMemoryIndex` with pre-filled packages and distributions.
|
||||
pub fn with(
|
||||
packages: FxOnceMap<PackageName, Arc<VersionsResponse>>,
|
||||
distributions: FxOnceMap<VersionId, Arc<MetadataResponse>>,
|
||||
) -> InMemoryIndex {
|
||||
InMemoryIndex(Arc::new(SharedInMemoryIndex {
|
||||
packages,
|
||||
distributions,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Returns a reference to the package metadata map.
|
||||
pub fn packages(&self) -> &FxOnceMap<PackageName, Arc<VersionsResponse>> {
|
||||
&self.0.packages
|
||||
|
||||
Reference in New Issue
Block a user