Skip to content

Commit 4407507

Browse files
committed
remove OnceLock from GlobalContext fields where the lazy loaded value is just a HashMap::defualt()
1 parent 745fcd6 commit 4407507

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/cargo/util/context/mod.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ pub struct GlobalContext {
212212
/// Environment variable snapshot.
213213
env: Env,
214214
/// Tracks which sources have been updated to avoid multiple updates.
215-
updated_sources: OnceLock<Mutex<HashSet<SourceId>>>,
215+
updated_sources: Mutex<HashSet<SourceId>>,
216216
/// Cache of credentials from configuration or credential providers.
217217
/// Maps from url to credential value.
218-
credential_cache: OnceLock<Mutex<HashMap<CanonicalUrl, CredentialCacheValue>>>,
218+
credential_cache: Mutex<HashMap<CanonicalUrl, CredentialCacheValue>>,
219219
/// Cache of registry config from the `[registries]` table.
220-
registry_config: OnceLock<Mutex<HashMap<SourceId, Option<RegistryConfig>>>>,
220+
registry_config: Mutex<HashMap<SourceId, Option<RegistryConfig>>>,
221221
/// Locks on the package and index caches.
222222
package_cache_lock: CacheLocker,
223223
/// Cached configuration parsed by Cargo
@@ -515,28 +515,19 @@ impl GlobalContext {
515515

516516
/// Which package sources have been updated, used to ensure it is only done once.
517517
pub fn updated_sources(&self) -> MutexGuard<'_, HashSet<SourceId>> {
518-
self.updated_sources
519-
.get_or_init(|| Default::default())
520-
.lock()
521-
.unwrap()
518+
self.updated_sources.lock().unwrap()
522519
}
523520

524521
/// Cached credentials from credential providers or configuration.
525522
pub fn credential_cache(&self) -> MutexGuard<'_, HashMap<CanonicalUrl, CredentialCacheValue>> {
526-
self.credential_cache
527-
.get_or_init(|| Default::default())
528-
.lock()
529-
.unwrap()
523+
self.credential_cache.lock().unwrap()
530524
}
531525

532526
/// Cache of already parsed registries from the `[registries]` table.
533527
pub(crate) fn registry_config(
534528
&self,
535529
) -> MutexGuard<'_, HashMap<SourceId, Option<RegistryConfig>>> {
536-
self.registry_config
537-
.get_or_init(|| Default::default())
538-
.lock()
539-
.unwrap()
530+
self.registry_config.lock().unwrap()
540531
}
541532

542533
/// Gets all config values from disk.

0 commit comments

Comments
 (0)