Skip to content

Commit

Permalink
Use a Boxed slice for version specifiers (#11766)
Browse files Browse the repository at this point in the history
## Summary

These are never modified, and we create _tons_ of them.
  • Loading branch information
charliermarsh authored Feb 25, 2025
1 parent a0b9f22 commit ce3654d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/uv-pep440/src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tracing::warn;
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
#[cfg_attr(feature = "rkyv", rkyv(derive(Debug)))]
pub struct VersionSpecifiers(Vec<VersionSpecifier>);
pub struct VersionSpecifiers(Box<[VersionSpecifier]>);

impl std::ops::Deref for VersionSpecifiers {
type Target = [VersionSpecifier];
Expand All @@ -43,7 +43,7 @@ impl std::ops::Deref for VersionSpecifiers {
impl VersionSpecifiers {
/// Matches all versions.
pub fn empty() -> Self {
Self(Vec::new())
Self(Box::new([]))
}

/// Whether all specifiers match the given version.
Expand All @@ -61,7 +61,7 @@ impl VersionSpecifiers {
// TODO(konsti): This seems better than sorting on insert and not getting the size hint,
// but i haven't measured it.
specifiers.sort_by(|a, b| a.version().cmp(b.version()));
Self(specifiers)
Self(specifiers.into_boxed_slice())
}

/// Returns the [`VersionSpecifiers`] whose union represents the given range.
Expand Down Expand Up @@ -117,7 +117,7 @@ impl IntoIterator for VersionSpecifiers {
type IntoIter = std::vec::IntoIter<VersionSpecifier>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
self.0.into_vec().into_iter()
}
}

Expand All @@ -131,7 +131,7 @@ impl FromStr for VersionSpecifiers {

impl From<VersionSpecifier> for VersionSpecifiers {
fn from(specifier: VersionSpecifier) -> Self {
Self(vec![specifier])
Self(Box::new([specifier]))
}
}

Expand Down Expand Up @@ -1285,7 +1285,7 @@ mod tests {
fn test_parse_version_specifiers() {
let result = VersionSpecifiers::from_str("~= 0.9, >= 1.0, != 1.3.4.*, < 2.0").unwrap();
assert_eq!(
result.0,
result.0.as_ref(),
[
VersionSpecifier {
operator: Operator::TildeEqual,
Expand Down

0 comments on commit ce3654d

Please sign in to comment.