From b1cabd00da5cc6b7f456248d5e213898b550a716 Mon Sep 17 00:00:00 2001 From: konstin Date: Sun, 22 Mar 2026 19:13:16 +0100 Subject: [PATCH] Ablation: replace Arc and deactivate VersionSmall Source ref: origin/konsti/no-version-arc-no-version-small Base: 00d72dac7b789d1c64ed21626175b80f4a1b8f2b --- crates/uv-pep440/src/version.rs | 86 ++++++--------------------------- 1 file changed, 15 insertions(+), 71 deletions(-) diff --git a/crates/uv-pep440/src/version.rs b/crates/uv-pep440/src/version.rs index 488e95c11..b9f3077df 100644 --- a/crates/uv-pep440/src/version.rs +++ b/crates/uv-pep440/src/version.rs @@ -8,7 +8,6 @@ use std::{ cmp::Ordering, hash::{Hash, Hasher}, str::FromStr, - sync::Arc, }; use uv_cache_key::{CacheKey, CacheKeyHasher}; @@ -286,7 +285,7 @@ pub struct Version { #[cfg_attr(feature = "rkyv", rkyv(derive(Debug, Eq, PartialEq, PartialOrd, Ord)))] enum VersionInner { Small { small: VersionSmall }, - Full { full: Arc }, + Full { full: Box }, } impl Version { @@ -303,8 +302,17 @@ impl Version { R: Borrow, { Self { - inner: VersionInner::Small { - small: VersionSmall::new(), + inner: VersionInner::Full { + full: Box::new(VersionFull { + epoch: 0, + release: vec![], + pre: None, + post: None, + dev: None, + local: LocalVersion::empty(), + min: None, + max: None, + }), }, } .with_release(release_numbers) @@ -505,7 +513,7 @@ impl Version { match &mut self.inner { VersionInner::Small { small } => small.clear_release(), VersionInner::Full { full } => { - Arc::make_mut(full).release.clear(); + full.release.clear(); } } } @@ -811,12 +819,12 @@ impl Version { }; *self = Self { inner: VersionInner::Full { - full: Arc::new(full), + full: Box::new(full), }, }; } match &mut self.inner { - VersionInner::Full { full } => Arc::make_mut(full), + VersionInner::Full { full } => full, VersionInner::Small { .. } => unreachable!(), } } @@ -1196,15 +1204,6 @@ impl VersionSmall { // the mask and the bit length above.) const SUFFIX_KIND_MASK: u64 = 0b1111; - #[inline] - fn new() -> Self { - Self { - _force_niche: NonZero::::MIN, - repr: Self::SUFFIX_NONE << Self::SUFFIX_VERSION_BIT_LEN, - len: 0, - } - } - #[inline] #[expect(clippy::unused_self)] fn epoch(&self) -> u64 { @@ -1985,9 +1984,6 @@ impl<'a> Parser<'a> { /// Parse a version pattern, which may be a verbatim version. fn parse_pattern(mut self) -> Result { - if let Some(vpat) = self.parse_fast() { - return Ok(vpat); - } self.bump_while(|byte| byte.is_ascii_whitespace()); self.bump_if("v"); self.parse_epoch_and_initial_release()?; @@ -2008,58 +2004,6 @@ impl<'a> Parser<'a> { Ok(self.into_pattern()) } - /// Attempts to do a "fast parse" of a version. - /// - /// This looks for versions of the form `w[.x[.y[.z]]]` while - /// simultaneously parsing numbers. This format corresponds to the - /// overwhelming majority of all version strings and can avoid most of the - /// work done in the more general parser. - /// - /// If the version string is not in the format of `w[.x[.y[.z]]]`, then - /// this returns `None`. - fn parse_fast(&self) -> Option { - let (mut prev_digit, mut cur, mut release, mut len) = (false, 0u8, [0u8; 4], 0u8); - for &byte in self.v { - if byte == b'.' { - if !prev_digit { - return None; - } - prev_digit = false; - *release.get_mut(usize::from(len))? = cur; - len += 1; - cur = 0; - } else { - let digit = byte.checked_sub(b'0')?; - if digit > 9 { - return None; - } - prev_digit = true; - cur = cur.checked_mul(10)?.checked_add(digit)?; - } - } - if !prev_digit { - return None; - } - *release.get_mut(usize::from(len))? = cur; - len += 1; - let small = VersionSmall { - _force_niche: NonZero::::MIN, - repr: (u64::from(release[0]) << 48) - | (u64::from(release[1]) << 40) - | (u64::from(release[2]) << 32) - | (u64::from(release[3]) << 24) - | (VersionSmall::SUFFIX_NONE << VersionSmall::SUFFIX_VERSION_BIT_LEN), - - len, - }; - let inner = VersionInner::Small { small }; - let version = Version { inner }; - Some(VersionPattern { - version, - wildcard: false, - }) - } - /// Parses an optional initial epoch number and the first component of the /// release part of a version number. In all cases, the first part of a /// version must be a single number, and if one isn't found, an error is base-commit: 00d72dac7b789d1c64ed21626175b80f4a1b8f2b -- 2.53.0