mirror of https://github.com/astral-sh/uv
Use a `SmallString` for the Yanked enum (#11715)
## Summary This is stored on `File`, which we create extensively. Easy way to reduce size.
This commit is contained in:
parent
1f7f9fdeb4
commit
4fc181dbf2
|
|
@ -5431,6 +5431,7 @@ dependencies = [
|
||||||
"uv-normalize",
|
"uv-normalize",
|
||||||
"uv-pep440",
|
"uv-pep440",
|
||||||
"uv-pep508",
|
"uv-pep508",
|
||||||
|
"uv-small-str",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ impl SimpleHtml {
|
||||||
let yanked = if let Some(yanked) = link.attributes().get("data-yanked").flatten() {
|
let yanked = if let Some(yanked) = link.attributes().get("data-yanked").flatten() {
|
||||||
let yanked = std::str::from_utf8(yanked.as_bytes())?;
|
let yanked = std::str::from_utf8(yanked.as_bytes())?;
|
||||||
let yanked = html_escape::decode_html_entities(yanked);
|
let yanked = html_escape::decode_html_entities(yanked);
|
||||||
Some(Yanked::Reason(yanked.to_string()))
|
Some(Yanked::Reason(yanked.into()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ uv-git-types = { workspace = true }
|
||||||
uv-normalize = { workspace = true }
|
uv-normalize = { workspace = true }
|
||||||
uv-pep440 = { workspace = true }
|
uv-pep440 = { workspace = true }
|
||||||
uv-pep508 = { workspace = true }
|
uv-pep508 = { workspace = true }
|
||||||
|
uv-small-str = { workspace = true }
|
||||||
|
|
||||||
hashbrown = { workspace = true }
|
hashbrown = { workspace = true }
|
||||||
indexmap = { workspace = true, features = ["serde"] }
|
indexmap = { workspace = true, features = ["serde"] }
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use jiff::Timestamp;
|
use jiff::Timestamp;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
|
|
||||||
use uv_pep440::{VersionSpecifiers, VersionSpecifiersParseError};
|
use uv_pep440::{VersionSpecifiers, VersionSpecifiersParseError};
|
||||||
|
use uv_small_str::SmallString;
|
||||||
|
|
||||||
use crate::lenient_requirement::LenientVersionSpecifiers;
|
use crate::lenient_requirement::LenientVersionSpecifiers;
|
||||||
|
|
||||||
|
|
@ -101,7 +103,7 @@ impl CoreMetadata {
|
||||||
#[rkyv(derive(Debug))]
|
#[rkyv(derive(Debug))]
|
||||||
pub enum Yanked {
|
pub enum Yanked {
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Reason(String),
|
Reason(SmallString),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Yanked {
|
impl<'de> Deserialize<'de> for Yanked {
|
||||||
|
|
@ -111,7 +113,7 @@ impl<'de> Deserialize<'de> for Yanked {
|
||||||
{
|
{
|
||||||
serde_untagged::UntaggedEnumVisitor::new()
|
serde_untagged::UntaggedEnumVisitor::new()
|
||||||
.bool(|bool| Ok(Yanked::Bool(bool)))
|
.bool(|bool| Ok(Yanked::Bool(bool)))
|
||||||
.string(|string| Ok(Yanked::Reason(string.to_owned())))
|
.string(|string| Ok(Yanked::Reason(SmallString::from(string))))
|
||||||
.deserialize(deserializer)
|
.deserialize(deserializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,7 +476,7 @@ impl ResolverOutput {
|
||||||
Some(Yanked::Reason(reason)) => {
|
Some(Yanked::Reason(reason)) => {
|
||||||
diagnostics.push(ResolutionDiagnostic::YankedVersion {
|
diagnostics.push(ResolutionDiagnostic::YankedVersion {
|
||||||
dist: dist.clone(),
|
dist: dist.clone(),
|
||||||
reason: Some(reason.clone()),
|
reason: Some(reason.to_string()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::cmp::PartialEq;
|
use std::cmp::PartialEq;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
|
@ -26,6 +27,15 @@ impl From<String> for SmallString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Cow<'_, str>> for SmallString {
|
||||||
|
fn from(s: Cow<'_, str>) -> Self {
|
||||||
|
match s {
|
||||||
|
Cow::Borrowed(s) => Self::from(s),
|
||||||
|
Cow::Owned(s) => Self::from(s),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<str> for SmallString {
|
impl AsRef<str> for SmallString {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue