refactor: remove some url to string clones (#30247)

This commit is contained in:
David Sherret 2025-07-31 10:10:29 -04:00 committed by GitHub
parent 1715fc5a7a
commit ae6ac919de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 27 additions and 28 deletions

4
cli/cache/check.rs vendored
View file

@ -92,7 +92,7 @@ impl TypeCheckCache {
.0 .0
.query_row( .query_row(
"SELECT text FROM tsbuildinfo WHERE specifier=?1 LIMIT 1", "SELECT text FROM tsbuildinfo WHERE specifier=?1 LIMIT 1",
params![specifier.to_string()], params![specifier.as_str()],
|row| Ok(row.get::<_, String>(0)?), |row| Ok(row.get::<_, String>(0)?),
) )
.ok()? .ok()?
@ -116,7 +116,7 @@ impl TypeCheckCache {
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
self.0.execute( self.0.execute(
"INSERT OR REPLACE INTO tsbuildinfo (specifier, text) VALUES (?1, ?2)", "INSERT OR REPLACE INTO tsbuildinfo (specifier, text) VALUES (?1, ?2)",
params![specifier.to_string(), text], params![specifier.as_str(), text],
)?; )?;
Ok(()) Ok(())
} }

View file

@ -853,7 +853,7 @@ impl ModuleRegistry {
{ {
format!("{text}{suffix}") format!("{text}{suffix}")
} else { } else {
url.to_string() url.into()
}; };
let text_edit = let text_edit =
Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit { Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {

View file

@ -423,7 +423,7 @@ fn format_message(
location.file.as_str(), location.file.as_str(),
current_dir current_dir
) )
.map(|url| deno_terminal::colors::cyan(url.to_string())) .map(|url| deno_terminal::colors::cyan(url.into()))
.unwrap_or(deno_terminal::colors::cyan(location.file.clone())), .unwrap_or(deno_terminal::colors::cyan(location.file.clone())),
deno_terminal::colors::yellow(location.line), deno_terminal::colors::yellow(location.line),
deno_terminal::colors::yellow(location.column) deno_terminal::colors::yellow(location.column)
@ -773,7 +773,7 @@ impl DenoPluginHandler {
); );
match result { match result {
Ok(specifier) => Ok(Some(file_path_or_url(&specifier)?)), Ok(specifier) => Ok(Some(file_path_or_url(specifier)?)),
Err(e) => { Err(e) => {
log::debug!("{}: {:?}", deno_terminal::colors::red("error"), e); log::debug!("{}: {:?}", deno_terminal::colors::red("error"), e);
Err(BundleError::Resolver(e)) Err(BundleError::Resolver(e))
@ -1000,16 +1000,16 @@ impl DenoPluginHandler {
} }
fn file_path_or_url( fn file_path_or_url(
url: &Url, url: Url,
) -> Result<String, deno_path_util::UrlToFilePathError> { ) -> Result<String, deno_path_util::UrlToFilePathError> {
if url.scheme() == "file" { if url.scheme() == "file" {
Ok( Ok(
deno_path_util::url_to_file_path(url)? deno_path_util::url_to_file_path(&url)?
.to_string_lossy() .to_string_lossy()
.into(), .into(),
) )
} else { } else {
Ok(url.to_string()) Ok(url.into())
} }
} }

View file

@ -306,7 +306,7 @@ impl deno_doc::html::HrefResolver for DocResolver {
if url.domain() == Some("deno.land") { if url.domain() == Some("deno.land") {
url.set_query(Some(&format!("s={}", symbol.join(".")))); url.set_query(Some(&format!("s={}", symbol.join("."))));
return Some(url.to_string()); return Some(url.into());
} }
None None

View file

@ -616,7 +616,7 @@ async fn resolve_shim_data(
} }
} }
executable_args.push(module_url.to_string()); executable_args.push(module_url.into());
executable_args.extend_from_slice(&install_flags_global.args); executable_args.extend_from_slice(&install_flags_global.args);
Ok(ShimData { Ok(ShimData {

View file

@ -132,7 +132,7 @@ impl HmrRunner {
let file_path = file_url.to_file_path().unwrap(); let file_path = file_url.to_file_path().unwrap();
if let Ok(canonicalized_file_path) = file_path.canonicalize() { if let Ok(canonicalized_file_path) = file_path.canonicalize() {
let canonicalized_file_url = Url::from_file_path(canonicalized_file_path).unwrap(); let canonicalized_file_url = Url::from_file_path(canonicalized_file_path).unwrap();
self.script_ids.insert(canonicalized_file_url.to_string(), params.script_id); self.script_ids.insert(canonicalized_file_url.into(), params.script_id);
} }
} }
} }

View file

@ -1202,7 +1202,7 @@ pub(crate) mod webtransport {
}; };
Ok(( Ok((
url.to_string(), url.into(),
connect_tx_rid, connect_tx_rid,
connect_rx_rid, connect_rx_rid,
settings_tx_rid, settings_tx_rid,

View file

@ -110,5 +110,5 @@ pub fn op_worker_threads_filename<
url_path.to_path_buf(), url_path.to_path_buf(),
)); ));
} }
Ok(Some(url.to_string())) Ok(Some(url.into()))
} }

View file

@ -268,7 +268,7 @@ pub fn op_blob_create_object_url(
let url = blob_store let url = blob_store
.insert_object_url(blob, maybe_location.map(|location| location.0.clone())); .insert_object_url(blob, maybe_location.map(|location| location.0.clone()));
Ok(url.to_string()) Ok(url.into())
} }
#[op2(fast)] #[op2(fast)]

View file

@ -226,13 +226,12 @@ async fn hyper_hello(port: u16) {
.await; .await;
} }
fn redirect_resp(url: String) -> Response<UnsyncBoxBody<Bytes, Infallible>> { fn redirect_resp(url: &str) -> Response<UnsyncBoxBody<Bytes, Infallible>> {
let mut redirect_resp = Response::new(UnsyncBoxBody::new(Empty::new())); let mut redirect_resp = Response::new(UnsyncBoxBody::new(Empty::new()));
*redirect_resp.status_mut() = StatusCode::MOVED_PERMANENTLY; *redirect_resp.status_mut() = StatusCode::MOVED_PERMANENTLY;
redirect_resp.headers_mut().insert( redirect_resp
http::header::LOCATION, .headers_mut()
HeaderValue::from_str(&url[..]).unwrap(), .insert(http::header::LOCATION, HeaderValue::from_str(url).unwrap());
);
redirect_resp redirect_resp
} }
@ -244,7 +243,7 @@ async fn redirect(
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{PORT}{p}"); let url = format!("http://localhost:{PORT}{p}");
Ok(redirect_resp(url)) Ok(redirect_resp(&url))
} }
async fn double_redirects( async fn double_redirects(
@ -254,7 +253,7 @@ async fn double_redirects(
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{REDIRECT_PORT}{p}"); let url = format!("http://localhost:{REDIRECT_PORT}{p}");
Ok(redirect_resp(url)) Ok(redirect_resp(&url))
} }
async fn inf_redirects( async fn inf_redirects(
@ -264,7 +263,7 @@ async fn inf_redirects(
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{INF_REDIRECTS_PORT}{p}"); let url = format!("http://localhost:{INF_REDIRECTS_PORT}{p}");
Ok(redirect_resp(url)) Ok(redirect_resp(&url))
} }
async fn another_redirect( async fn another_redirect(
@ -274,7 +273,7 @@ async fn another_redirect(
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{PORT}/subdir{p}"); let url = format!("http://localhost:{PORT}/subdir{p}");
Ok(redirect_resp(url)) Ok(redirect_resp(&url))
} }
async fn auth_redirect( async fn auth_redirect(
@ -289,7 +288,7 @@ async fn auth_redirect(
let p = req.uri().path(); let p = req.uri().path();
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{PORT}{p}"); let url = format!("http://localhost:{PORT}{p}");
return Ok(redirect_resp(url)); return Ok(redirect_resp(&url));
} }
} }
@ -312,7 +311,7 @@ async fn basic_auth_redirect(
let p = req.uri().path(); let p = req.uri().path();
assert_eq!(&p[0..1], "/"); assert_eq!(&p[0..1], "/");
let url = format!("http://localhost:{PORT}{p}"); let url = format!("http://localhost:{PORT}{p}");
return Ok(redirect_resp(url)); return Ok(redirect_resp(&url));
} }
} }
@ -421,21 +420,21 @@ async fn absolute_redirect(
.collect(); .collect();
if let Some(url) = query_params.get("redirect_to") { if let Some(url) = query_params.get("redirect_to") {
let redirect = redirect_resp(url.to_owned()); let redirect = redirect_resp(url);
return Ok(redirect); return Ok(redirect);
} }
} }
if path.starts_with("/REDIRECT") { if path.starts_with("/REDIRECT") {
let url = &req.uri().path()[9..]; let url = &req.uri().path()[9..];
let redirect = redirect_resp(url.to_string()); let redirect = redirect_resp(url);
return Ok(redirect); return Ok(redirect);
} }
if path.starts_with("/a/b/c") { if path.starts_with("/a/b/c") {
if let Some(x_loc) = req.headers().get("x-location") { if let Some(x_loc) = req.headers().get("x-location") {
let loc = x_loc.to_str().unwrap(); let loc = x_loc.to_str().unwrap();
return Ok(redirect_resp(loc.to_string())); return Ok(redirect_resp(loc));
} }
} }