Skip to content

Commit 272ab3d

Browse files
committed
Use arcstr in verbatim URL
1 parent 24a5920 commit 272ab3d

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

crates/uv-distribution-types/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1343,10 +1343,10 @@ mod test {
13431343
/// Ensure that we don't accidentally grow the `Dist` sizes.
13441344
#[test]
13451345
fn dist_size() {
1346-
assert!(size_of::<Dist>() <= 248, "{}", size_of::<Dist>());
1346+
assert!(size_of::<Dist>() <= 232, "{}", size_of::<Dist>());
13471347
assert!(size_of::<BuiltDist>() <= 216, "{}", size_of::<BuiltDist>());
13481348
assert!(
1349-
size_of::<SourceDist>() <= 248,
1349+
size_of::<SourceDist>() <= 232,
13501350
"{}",
13511351
size_of::<SourceDist>()
13521352
);

crates/uv-pep508/src/unnamed.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait UnnamedRequirementUrl: Pep508Url {
2929

3030
/// Set the verbatim representation of the URL.
3131
#[must_use]
32-
fn with_given(self, given: impl Into<String>) -> Self;
32+
fn with_given(self, given: impl AsRef<str>) -> Self;
3333

3434
/// Return the original string as given by the user, if available.
3535
fn given(&self) -> Option<&str>;
@@ -51,7 +51,7 @@ impl UnnamedRequirementUrl for VerbatimUrl {
5151
Ok(Self::parse_url(given)?)
5252
}
5353

54-
fn with_given(self, given: impl Into<String>) -> Self {
54+
fn with_given(self, given: impl AsRef<str>) -> Self {
5555
self.with_given(given)
5656
}
5757

@@ -258,7 +258,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
258258
len,
259259
input: cursor.to_string(),
260260
})?
261-
.with_given(url.to_string());
261+
.with_given(url);
262262
return Ok((url, extras));
263263
}
264264

@@ -269,7 +269,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
269269
len,
270270
input: cursor.to_string(),
271271
})?
272-
.with_given(url.to_string());
272+
.with_given(url);
273273
Ok((url, extras))
274274
}
275275
// Ex) `https://download.pytorch.org/whl/torch_stable.html`
@@ -282,7 +282,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
282282
len,
283283
input: cursor.to_string(),
284284
})?
285-
.with_given(url.to_string());
285+
.with_given(url);
286286
Ok((url, extras))
287287
}
288288

@@ -296,7 +296,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
296296
len,
297297
input: cursor.to_string(),
298298
})?
299-
.with_given(url.to_string());
299+
.with_given(url);
300300
return Ok((url, extras));
301301
}
302302

@@ -307,7 +307,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
307307
len,
308308
input: cursor.to_string(),
309309
})?
310-
.with_given(url.to_string());
310+
.with_given(url);
311311
Ok((url, extras))
312312
}
313313
}
@@ -321,7 +321,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
321321
len,
322322
input: cursor.to_string(),
323323
})?
324-
.with_given(url.to_string());
324+
.with_given(url);
325325
return Ok((url, extras));
326326
}
327327

@@ -332,7 +332,7 @@ fn preprocess_unnamed_url<Url: UnnamedRequirementUrl>(
332332
len,
333333
input: cursor.to_string(),
334334
})?
335-
.with_given(url.to_string());
335+
.with_given(url);
336336
Ok((url, extras))
337337
}
338338
}

crates/uv-pep508/src/verbatim_url.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use regex::Regex;
21
use std::borrow::Cow;
32
use std::cmp::Ordering;
43
use std::fmt::Debug;
54
use std::hash::Hash;
65
use std::ops::Deref;
76
use std::path::{Path, PathBuf};
87
use std::sync::LazyLock;
8+
9+
use arcstr::ArcStr;
10+
use regex::Regex;
911
use thiserror::Error;
1012
use url::{ParseError, Url};
1113

@@ -19,7 +21,7 @@ pub struct VerbatimUrl {
1921
/// The parsed URL.
2022
url: Url,
2123
/// The URL as it was provided by the user.
22-
given: Option<String>,
24+
given: Option<ArcStr>,
2325
}
2426

2527
impl Hash for VerbatimUrl {
@@ -112,9 +114,9 @@ impl VerbatimUrl {
112114

113115
/// Set the verbatim representation of the URL.
114116
#[must_use]
115-
pub fn with_given(self, given: impl Into<String>) -> Self {
117+
pub fn with_given(self, given: impl AsRef<str>) -> Self {
116118
Self {
117-
given: Some(given.into()),
119+
given: Some(ArcStr::from(given.as_ref())),
118120
..self
119121
}
120122
}
@@ -232,21 +234,21 @@ impl Pep508Url for VerbatimUrl {
232234
let path = normalize_url_path(path);
233235

234236
if let Some(working_dir) = working_dir {
235-
return Ok(VerbatimUrl::from_path(path.as_ref(), working_dir)?
236-
.with_given(url.to_string()));
237+
return Ok(
238+
VerbatimUrl::from_path(path.as_ref(), working_dir)?.with_given(url)
239+
);
237240
}
238241

239-
Ok(VerbatimUrl::from_absolute_path(path.as_ref())?
240-
.with_given(url.to_string()))
242+
Ok(VerbatimUrl::from_absolute_path(path.as_ref())?.with_given(url))
241243
}
242244
#[cfg(not(feature = "non-pep508-extensions"))]
243-
Ok(VerbatimUrl::parse_url(expanded)?.with_given(url.to_string()))
245+
Ok(VerbatimUrl::parse_url(expanded)?.with_given(url))
244246
}
245247

246248
// Ex) `https://download.pytorch.org/whl/torch_stable.html`
247249
Some(_) => {
248250
// Ex) `https://download.pytorch.org/whl/torch_stable.html`
249-
Ok(VerbatimUrl::parse_url(expanded.as_ref())?.with_given(url.to_string()))
251+
Ok(VerbatimUrl::parse_url(expanded.as_ref())?.with_given(url))
250252
}
251253

252254
// Ex) `C:\Users\ferris\wheel-0.42.0.tar.gz`
@@ -255,11 +257,10 @@ impl Pep508Url for VerbatimUrl {
255257
{
256258
if let Some(working_dir) = working_dir {
257259
return Ok(VerbatimUrl::from_path(expanded.as_ref(), working_dir)?
258-
.with_given(url.to_string()));
260+
.with_given(url));
259261
}
260262

261-
Ok(VerbatimUrl::from_absolute_path(expanded.as_ref())?
262-
.with_given(url.to_string()))
263+
Ok(VerbatimUrl::from_absolute_path(expanded.as_ref())?.with_given(url))
263264
}
264265
#[cfg(not(feature = "non-pep508-extensions"))]
265266
Err(Self::Err::NotAUrl(expanded.to_string()))
@@ -270,11 +271,12 @@ impl Pep508Url for VerbatimUrl {
270271
#[cfg(feature = "non-pep508-extensions")]
271272
{
272273
if let Some(working_dir) = working_dir {
273-
return Ok(VerbatimUrl::from_path(expanded.as_ref(), working_dir)?
274-
.with_given(url.to_string()));
274+
return Ok(
275+
VerbatimUrl::from_path(expanded.as_ref(), working_dir)?.with_given(url)
276+
);
275277
}
276278

277-
Ok(VerbatimUrl::from_absolute_path(expanded.as_ref())?.with_given(url.to_string()))
279+
Ok(VerbatimUrl::from_absolute_path(expanded.as_ref())?.with_given(url))
278280
}
279281

280282
#[cfg(not(feature = "non-pep508-extensions"))]

crates/uv-pypi-types/src/parsed_url.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
133133
})
134134
}
135135

136-
fn with_given(self, given: impl Into<String>) -> Self {
136+
fn with_given(self, given: impl AsRef<str>) -> Self {
137137
Self {
138138
verbatim: self.verbatim.with_given(given),
139139
..self

0 commit comments

Comments
 (0)