summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorYiyu Lin <linyiyu1992@gmail.com>2023-01-04 20:20:36 +0800
committerGitHub <noreply@github.com>2023-01-04 13:20:36 +0100
commit319f6074761421b797db71bf10f6171516e3d92a (patch)
tree86d67cc767861e826fff6f2d41c243dbbcd25f60 /cli
parent2da882137eecc96e73a8c4f8e9b7d59ccdbfca66 (diff)
chore(cli,ext,rt): remove some unnecessary `clone` or `malloc` (#17261)
Diffstat (limited to 'cli')
-rw-r--r--cli/build.rs2
-rw-r--r--cli/file_fetcher.rs6
-rw-r--r--cli/tools/check.rs18
-rw-r--r--cli/tsc/diagnostics.rs4
4 files changed, 19 insertions, 11 deletions
diff --git a/cli/build.rs b/cli/build.rs
index 5ef2296e8..faeaed073 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -1,11 +1,11 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-use deno_core::Extension;
use std::env;
use std::path::Path;
use std::path::PathBuf;
use deno_core::snapshot_util::*;
+use deno_core::Extension;
use deno_runtime::deno_cache::SqliteBackedCache;
use deno_runtime::permissions::Permissions;
use deno_runtime::*;
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index b8ee82a80..cc83e6f5f 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -90,7 +90,7 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result<File, AnyError> {
let local = specifier.to_file_path().map_err(|_| {
uri_error(format!("Invalid file path.\n Specifier: {}", specifier))
})?;
- let bytes = fs::read(local.clone())?;
+ let bytes = fs::read(&local)?;
let charset = text_encoding::detect_charset(&bytes).to_string();
let source = get_source_from_bytes(bytes, Some(charset))?;
let media_type = MediaType::from(specifier);
@@ -359,7 +359,7 @@ impl FileFetcher {
let blob = {
let blob_store = self.blob_store.borrow();
blob_store
- .get_object_url(specifier.clone())?
+ .get_object_url(specifier.clone())
.ok_or_else(|| {
custom_error(
"NotFound",
@@ -525,7 +525,7 @@ impl FileFetcher {
CacheSetting::ReloadSome(list) => {
let mut url = specifier.clone();
url.set_fragment(None);
- if list.contains(&url.as_str().to_string()) {
+ if list.iter().any(|x| x == url.as_str()) {
return false;
}
url.set_query(None);
diff --git a/cli/tools/check.rs b/cli/tools/check.rs
index e3fb664ad..0c57af0b0 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -79,10 +79,10 @@ pub fn check(
let root_names = get_tsc_roots(&segment_graph_data, check_js);
if options.log_checks {
for (root, _) in roots {
- let root_str = root.to_string();
+ let root_str = root.as_str();
// `$deno` specifiers are internal, don't print them.
if !root_str.contains("$deno") {
- log::info!("{} {}", colors::green("Check"), root);
+ log::info!("{} {}", colors::green("Check"), root_str);
}
}
}
@@ -116,12 +116,20 @@ pub fn check(
let diagnostics = if options.type_check_mode == TypeCheckMode::Local {
response.diagnostics.filter(|d| {
if let Some(file_name) = &d.file_name {
- !file_name.starts_with("http")
- && ModuleSpecifier::parse(file_name)
+ if !file_name.starts_with("http") {
+ if ModuleSpecifier::parse(file_name)
.map(|specifier| !npm_resolver.in_npm_package(&specifier))
.unwrap_or(true)
+ {
+ Some(d.clone())
+ } else {
+ None
+ }
+ } else {
+ None
+ }
} else {
- true
+ Some(d.clone())
}
})
} else {
diff --git a/cli/tsc/diagnostics.rs b/cli/tsc/diagnostics.rs
index 4cd6564cb..fb7304c9b 100644
--- a/cli/tsc/diagnostics.rs
+++ b/cli/tsc/diagnostics.rs
@@ -340,9 +340,9 @@ impl Diagnostics {
/// returns `true` are included.
pub fn filter<P>(&self, predicate: P) -> Self
where
- P: FnMut(&Diagnostic) -> bool,
+ P: FnMut(&Diagnostic) -> Option<Diagnostic>,
{
- let diagnostics = self.0.clone().into_iter().filter(predicate).collect();
+ let diagnostics = self.0.iter().filter_map(predicate).collect();
Self(diagnostics)
}