mirror of https://github.com/astral-sh/uv
Use a Boxed slice for version specifiers (#11766)
## Summary These are never modified, and we create _tons_ of them.
This commit is contained in:
parent
a0b9f22a21
commit
ce3654da77
|
|
@ -30,7 +30,7 @@ use tracing::warn;
|
||||||
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
|
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "rkyv", rkyv(derive(Debug)))]
|
#[cfg_attr(feature = "rkyv", rkyv(derive(Debug)))]
|
||||||
pub struct VersionSpecifiers(Vec<VersionSpecifier>);
|
pub struct VersionSpecifiers(Box<[VersionSpecifier]>);
|
||||||
|
|
||||||
impl std::ops::Deref for VersionSpecifiers {
|
impl std::ops::Deref for VersionSpecifiers {
|
||||||
type Target = [VersionSpecifier];
|
type Target = [VersionSpecifier];
|
||||||
|
|
@ -43,7 +43,7 @@ impl std::ops::Deref for VersionSpecifiers {
|
||||||
impl VersionSpecifiers {
|
impl VersionSpecifiers {
|
||||||
/// Matches all versions.
|
/// Matches all versions.
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self(Vec::new())
|
Self(Box::new([]))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether all specifiers match the given version.
|
/// Whether all specifiers match the given version.
|
||||||
|
|
@ -61,7 +61,7 @@ impl VersionSpecifiers {
|
||||||
// TODO(konsti): This seems better than sorting on insert and not getting the size hint,
|
// TODO(konsti): This seems better than sorting on insert and not getting the size hint,
|
||||||
// but i haven't measured it.
|
// but i haven't measured it.
|
||||||
specifiers.sort_by(|a, b| a.version().cmp(b.version()));
|
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.
|
/// Returns the [`VersionSpecifiers`] whose union represents the given range.
|
||||||
|
|
@ -117,7 +117,7 @@ impl IntoIterator for VersionSpecifiers {
|
||||||
type IntoIter = std::vec::IntoIter<VersionSpecifier>;
|
type IntoIter = std::vec::IntoIter<VersionSpecifier>;
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.0.into_iter()
|
self.0.into_vec().into_iter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ impl FromStr for VersionSpecifiers {
|
||||||
|
|
||||||
impl From<VersionSpecifier> for VersionSpecifiers {
|
impl From<VersionSpecifier> for VersionSpecifiers {
|
||||||
fn from(specifier: VersionSpecifier) -> Self {
|
fn from(specifier: VersionSpecifier) -> Self {
|
||||||
Self(vec![specifier])
|
Self(Box::new([specifier]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1285,7 +1285,7 @@ mod tests {
|
||||||
fn test_parse_version_specifiers() {
|
fn test_parse_version_specifiers() {
|
||||||
let result = VersionSpecifiers::from_str("~= 0.9, >= 1.0, != 1.3.4.*, < 2.0").unwrap();
|
let result = VersionSpecifiers::from_str("~= 0.9, >= 1.0, != 1.3.4.*, < 2.0").unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.0,
|
result.0.as_ref(),
|
||||||
[
|
[
|
||||||
VersionSpecifier {
|
VersionSpecifier {
|
||||||
operator: Operator::TildeEqual,
|
operator: Operator::TildeEqual,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue