mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
refactor: remove some url to string clones (#30247)
This commit is contained in:
parent
1715fc5a7a
commit
ae6ac919de
10 changed files with 27 additions and 28 deletions
4
cli/cache/check.rs
vendored
4
cli/cache/check.rs
vendored
|
@ -92,7 +92,7 @@ impl TypeCheckCache {
|
|||
.0
|
||||
.query_row(
|
||||
"SELECT text FROM tsbuildinfo WHERE specifier=?1 LIMIT 1",
|
||||
params![specifier.to_string()],
|
||||
params![specifier.as_str()],
|
||||
|row| Ok(row.get::<_, String>(0)?),
|
||||
)
|
||||
.ok()?
|
||||
|
@ -116,7 +116,7 @@ impl TypeCheckCache {
|
|||
) -> Result<(), AnyError> {
|
||||
self.0.execute(
|
||||
"INSERT OR REPLACE INTO tsbuildinfo (specifier, text) VALUES (?1, ?2)",
|
||||
params![specifier.to_string(), text],
|
||||
params![specifier.as_str(), text],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -853,7 +853,7 @@ impl ModuleRegistry {
|
|||
{
|
||||
format!("{text}{suffix}")
|
||||
} else {
|
||||
url.to_string()
|
||||
url.into()
|
||||
};
|
||||
let text_edit =
|
||||
Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
|
||||
|
|
|
@ -423,7 +423,7 @@ fn format_message(
|
|||
location.file.as_str(),
|
||||
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())),
|
||||
deno_terminal::colors::yellow(location.line),
|
||||
deno_terminal::colors::yellow(location.column)
|
||||
|
@ -773,7 +773,7 @@ impl DenoPluginHandler {
|
|||
);
|
||||
|
||||
match result {
|
||||
Ok(specifier) => Ok(Some(file_path_or_url(&specifier)?)),
|
||||
Ok(specifier) => Ok(Some(file_path_or_url(specifier)?)),
|
||||
Err(e) => {
|
||||
log::debug!("{}: {:?}", deno_terminal::colors::red("error"), e);
|
||||
Err(BundleError::Resolver(e))
|
||||
|
@ -1000,16 +1000,16 @@ impl DenoPluginHandler {
|
|||
}
|
||||
|
||||
fn file_path_or_url(
|
||||
url: &Url,
|
||||
url: Url,
|
||||
) -> Result<String, deno_path_util::UrlToFilePathError> {
|
||||
if url.scheme() == "file" {
|
||||
Ok(
|
||||
deno_path_util::url_to_file_path(url)?
|
||||
deno_path_util::url_to_file_path(&url)?
|
||||
.to_string_lossy()
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
Ok(url.to_string())
|
||||
Ok(url.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ impl deno_doc::html::HrefResolver for DocResolver {
|
|||
|
||||
if url.domain() == Some("deno.land") {
|
||||
url.set_query(Some(&format!("s={}", symbol.join("."))));
|
||||
return Some(url.to_string());
|
||||
return Some(url.into());
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
@ -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);
|
||||
|
||||
Ok(ShimData {
|
||||
|
|
|
@ -132,7 +132,7 @@ impl HmrRunner {
|
|||
let file_path = file_url.to_file_path().unwrap();
|
||||
if let Ok(canonicalized_file_path) = file_path.canonicalize() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1202,7 +1202,7 @@ pub(crate) mod webtransport {
|
|||
};
|
||||
|
||||
Ok((
|
||||
url.to_string(),
|
||||
url.into(),
|
||||
connect_tx_rid,
|
||||
connect_rx_rid,
|
||||
settings_tx_rid,
|
||||
|
|
|
@ -110,5 +110,5 @@ pub fn op_worker_threads_filename<
|
|||
url_path.to_path_buf(),
|
||||
));
|
||||
}
|
||||
Ok(Some(url.to_string()))
|
||||
Ok(Some(url.into()))
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ pub fn op_blob_create_object_url(
|
|||
let url = blob_store
|
||||
.insert_object_url(blob, maybe_location.map(|location| location.0.clone()));
|
||||
|
||||
Ok(url.to_string())
|
||||
Ok(url.into())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
|
|
|
@ -226,13 +226,12 @@ async fn hyper_hello(port: u16) {
|
|||
.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()));
|
||||
*redirect_resp.status_mut() = StatusCode::MOVED_PERMANENTLY;
|
||||
redirect_resp.headers_mut().insert(
|
||||
http::header::LOCATION,
|
||||
HeaderValue::from_str(&url[..]).unwrap(),
|
||||
);
|
||||
redirect_resp
|
||||
.headers_mut()
|
||||
.insert(http::header::LOCATION, HeaderValue::from_str(url).unwrap());
|
||||
|
||||
redirect_resp
|
||||
}
|
||||
|
@ -244,7 +243,7 @@ async fn redirect(
|
|||
assert_eq!(&p[0..1], "/");
|
||||
let url = format!("http://localhost:{PORT}{p}");
|
||||
|
||||
Ok(redirect_resp(url))
|
||||
Ok(redirect_resp(&url))
|
||||
}
|
||||
|
||||
async fn double_redirects(
|
||||
|
@ -254,7 +253,7 @@ async fn double_redirects(
|
|||
assert_eq!(&p[0..1], "/");
|
||||
let url = format!("http://localhost:{REDIRECT_PORT}{p}");
|
||||
|
||||
Ok(redirect_resp(url))
|
||||
Ok(redirect_resp(&url))
|
||||
}
|
||||
|
||||
async fn inf_redirects(
|
||||
|
@ -264,7 +263,7 @@ async fn inf_redirects(
|
|||
assert_eq!(&p[0..1], "/");
|
||||
let url = format!("http://localhost:{INF_REDIRECTS_PORT}{p}");
|
||||
|
||||
Ok(redirect_resp(url))
|
||||
Ok(redirect_resp(&url))
|
||||
}
|
||||
|
||||
async fn another_redirect(
|
||||
|
@ -274,7 +273,7 @@ async fn another_redirect(
|
|||
assert_eq!(&p[0..1], "/");
|
||||
let url = format!("http://localhost:{PORT}/subdir{p}");
|
||||
|
||||
Ok(redirect_resp(url))
|
||||
Ok(redirect_resp(&url))
|
||||
}
|
||||
|
||||
async fn auth_redirect(
|
||||
|
@ -289,7 +288,7 @@ async fn auth_redirect(
|
|||
let p = req.uri().path();
|
||||
assert_eq!(&p[0..1], "/");
|
||||
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();
|
||||
assert_eq!(&p[0..1], "/");
|
||||
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();
|
||||
|
||||
if let Some(url) = query_params.get("redirect_to") {
|
||||
let redirect = redirect_resp(url.to_owned());
|
||||
let redirect = redirect_resp(url);
|
||||
return Ok(redirect);
|
||||
}
|
||||
}
|
||||
|
||||
if path.starts_with("/REDIRECT") {
|
||||
let url = &req.uri().path()[9..];
|
||||
let redirect = redirect_resp(url.to_string());
|
||||
let redirect = redirect_resp(url);
|
||||
return Ok(redirect);
|
||||
}
|
||||
|
||||
if path.starts_with("/a/b/c") {
|
||||
if let Some(x_loc) = req.headers().get("x-location") {
|
||||
let loc = x_loc.to_str().unwrap();
|
||||
return Ok(redirect_resp(loc.to_string()));
|
||||
return Ok(redirect_resp(loc));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue