From 1cff7c377498a2a4e7c0bbd1773154426918aeab Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 12 Feb 2024 10:31:03 -0500 Subject: [PATCH] platform-tags: make Tags use an Arc internally This makes cloning and thus sharing across multiple threads much cheaper. Since Tags is conceptually immutable once it is constructed, this doesn't pose an issue and shouldn't introduce any additional costs. --- crates/platform-tags/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/platform-tags/src/lib.rs b/crates/platform-tags/src/lib.rs index 72f19ba7d..6bbd4c285 100644 --- a/crates/platform-tags/src/lib.rs +++ b/crates/platform-tags/src/lib.rs @@ -1,5 +1,6 @@ use std::num::NonZeroU32; use std::str::FromStr; +use std::sync::Arc; use rustc_hash::FxHashMap; @@ -24,7 +25,8 @@ pub enum TagsError { #[derive(Debug, Clone)] pub struct Tags { /// python_tag |--> abi_tag |--> platform_tag |--> priority - map: FxHashMap>>, + #[allow(clippy::type_complexity)] + map: Arc>>>, } impl Tags { @@ -42,7 +44,7 @@ impl Tags { .entry(platform.to_string()) .or_insert(TagPriority::try_from(index).expect("valid tag priority")); } - Self { map } + Self { map: Arc::new(map) } } /// Returns the compatible tags for the given Python implementation (e.g., `cpython`), version,