Skip to content

Commit 3fd0af4

Browse files
susitsmepage
authored andcommitted
remove OnceLock from GlobalContext fields where the lazy loaded value is just a HashMap::defualt()
1 parent a8d9b7d commit 3fd0af4

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
@@ -210,12 +210,12 @@ pub struct GlobalContext {
210210
/// Environment variable snapshot.
211211
env: Env,
212212
/// Tracks which sources have been updated to avoid multiple updates.
213-
updated_sources: OnceLock<Mutex<HashSet<SourceId>>>,
213+
updated_sources: Mutex<HashSet<SourceId>>,
214214
/// Cache of credentials from configuration or credential providers.
215215
/// Maps from url to credential value.
216-
credential_cache: OnceLock<Mutex<HashMap<CanonicalUrl, CredentialCacheValue>>>,
216+
credential_cache: Mutex<HashMap<CanonicalUrl, CredentialCacheValue>>,
217217
/// Cache of registry config from the `[registries]` table.
218-
registry_config: OnceLock<Mutex<HashMap<SourceId, Option<RegistryConfig>>>>,
218+
registry_config: Mutex<HashMap<SourceId, Option<RegistryConfig>>>,
219219
/// Locks on the package and index caches.
220220
package_cache_lock: CacheLocker,
221221
/// Cached configuration parsed by Cargo
@@ -524,28 +524,19 @@ impl GlobalContext {
524524

525525
/// Which package sources have been updated, used to ensure it is only done once.
526526
pub fn updated_sources(&self) -> MutexGuard<'_, HashSet<SourceId>> {
527-
self.updated_sources
528-
.get_or_init(|| Default::default())
529-
.lock()
530-
.unwrap()
527+
self.updated_sources.lock().unwrap()
531528
}
532529

533530
/// Cached credentials from credential providers or configuration.
534531
pub fn credential_cache(&self) -> MutexGuard<'_, HashMap<CanonicalUrl, CredentialCacheValue>> {
535-
self.credential_cache
536-
.get_or_init(|| Default::default())
537-
.lock()
538-
.unwrap()
532+
self.credential_cache.lock().unwrap()
539533
}
540534

541535
/// Cache of already parsed registries from the `[registries]` table.
542536
pub(crate) fn registry_config(
543537
&self,
544538
) -> MutexGuard<'_, HashMap<SourceId, Option<RegistryConfig>>> {
545-
self.registry_config
546-
.get_or_init(|| Default::default())
547-
.lock()
548-
.unwrap()
539+
self.registry_config.lock().unwrap()
549540
}
550541

551542
/// Gets all config values from disk.

0 commit comments

Comments
 (0)