Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a SmallString for the Yanked enum #11715

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/uv-client/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl SimpleHtml {
let yanked = if let Some(yanked) = link.attributes().get("data-yanked").flatten() {
let yanked = std::str::from_utf8(yanked.as_bytes())?;
let yanked = html_escape::decode_html_entities(yanked);
Some(Yanked::Reason(yanked.to_string()))
Some(Yanked::Reason(yanked.into()))
} else {
None
};
Expand Down
1 change: 1 addition & 0 deletions crates/uv-pypi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ uv-git-types = { workspace = true }
uv-normalize = { workspace = true }
uv-pep440 = { workspace = true }
uv-pep508 = { workspace = true }
uv-small-str = { workspace = true }

hashbrown = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
Expand Down
6 changes: 4 additions & 2 deletions crates/uv-pypi-types/src/simple_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::str::FromStr;

use jiff::Timestamp;
use serde::{Deserialize, Deserializer, Serialize};

use uv_pep440::{VersionSpecifiers, VersionSpecifiersParseError};
use uv_small_str::SmallString;

use crate::lenient_requirement::LenientVersionSpecifiers;

Expand Down Expand Up @@ -101,7 +103,7 @@ impl CoreMetadata {
#[rkyv(derive(Debug))]
pub enum Yanked {
Bool(bool),
Reason(String),
Reason(SmallString),
}

impl<'de> Deserialize<'de> for Yanked {
Expand All @@ -111,7 +113,7 @@ impl<'de> Deserialize<'de> for Yanked {
{
serde_untagged::UntaggedEnumVisitor::new()
.bool(|bool| Ok(Yanked::Bool(bool)))
.string(|string| Ok(Yanked::Reason(string.to_owned())))
.string(|string| Ok(Yanked::Reason(SmallString::from(string))))
.deserialize(deserializer)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolution/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl ResolverOutput {
Some(Yanked::Reason(reason)) => {
diagnostics.push(ResolutionDiagnostic::YankedVersion {
dist: dist.clone(),
reason: Some(reason.clone()),
reason: Some(reason.to_string()),
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions crates/uv-small-str/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::cmp::PartialEq;
use std::ops::Deref;

Expand Down Expand Up @@ -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 {
#[inline]
fn as_ref(&self) -> &str {
Expand Down
Loading