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.
This commit is contained in:
Andrew Gallant
2024-02-12 10:31:03 -05:00
committed by Andrew Gallant
parent bdb491baf6
commit 1cff7c3774
+4 -2
View File
@@ -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<String, FxHashMap<String, FxHashMap<String, TagPriority>>>,
#[allow(clippy::type_complexity)]
map: Arc<FxHashMap<String, FxHashMap<String, FxHashMap<String, TagPriority>>>>,
}
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,