mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 04:48:18 +00:00
Avoid allocating when stripping source distribution extension (#10625)
This commit is contained in:
parent
9e06aa89ec
commit
a7fe84aa03
2 changed files with 18 additions and 13 deletions
|
|
@ -83,19 +83,24 @@ impl SourceDistExtension {
|
|||
_ => Err(ExtensionError::SourceDist),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the name for the extension.
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Zip => "zip",
|
||||
Self::TarGz => "tar.gz",
|
||||
Self::TarBz2 => "tar.bz2",
|
||||
Self::TarXz => "tar.xz",
|
||||
Self::TarZst => "tar.zst",
|
||||
Self::TarLzma => "tar.lzma",
|
||||
Self::Tar => "tar",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SourceDistExtension {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Zip => f.write_str("zip"),
|
||||
Self::TarGz => f.write_str("tar.gz"),
|
||||
Self::TarBz2 => f.write_str("tar.bz2"),
|
||||
Self::TarXz => f.write_str("tar.xz"),
|
||||
Self::TarZst => f.write_str("tar.zst"),
|
||||
Self::TarLzma => f.write_str("tar.lzma"),
|
||||
Self::Tar => f.write_str("tar"),
|
||||
}
|
||||
f.write_str(self.name())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ impl SourceDistFilename {
|
|||
package_name: &PackageName,
|
||||
) -> Result<Self, SourceDistFilenameError> {
|
||||
// Drop the extension (e.g., given `tar.gz`, drop `.tar.gz`).
|
||||
if filename.len() <= extension.to_string().len() + 1 {
|
||||
if filename.len() <= extension.name().len() + 1 {
|
||||
return Err(SourceDistFilenameError {
|
||||
filename: filename.to_string(),
|
||||
kind: SourceDistFilenameErrorKind::Extension,
|
||||
});
|
||||
}
|
||||
|
||||
let stem = &filename[..(filename.len() - (extension.to_string().len() + 1))];
|
||||
let stem = &filename[..(filename.len() - (extension.name().len() + 1))];
|
||||
|
||||
if stem.len() <= package_name.as_ref().len() + "-".len() {
|
||||
return Err(SourceDistFilenameError {
|
||||
|
|
@ -94,14 +94,14 @@ impl SourceDistFilename {
|
|||
};
|
||||
|
||||
// Drop the extension (e.g., given `tar.gz`, drop `.tar.gz`).
|
||||
if filename.len() <= extension.to_string().len() + 1 {
|
||||
if filename.len() <= extension.name().len() + 1 {
|
||||
return Err(SourceDistFilenameError {
|
||||
filename: filename.to_string(),
|
||||
kind: SourceDistFilenameErrorKind::Extension,
|
||||
});
|
||||
}
|
||||
|
||||
let stem = &filename[..(filename.len() - (extension.to_string().len() + 1))];
|
||||
let stem = &filename[..(filename.len() - (extension.name().len() + 1))];
|
||||
|
||||
let Some((package_name, version)) = stem.rsplit_once('-') else {
|
||||
return Err(SourceDistFilenameError {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue