1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

refactor(cli): fewer clones (#17450)

This commit is contained in:
Geert-Jan Zwiers 2023-01-16 21:27:41 +01:00 committed by GitHub
parent 40527526e5
commit e023a6e3f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 36 deletions

View file

@ -29,12 +29,7 @@ use tower_lsp::lsp_types::Range;
/// Diagnostic error codes which actually are the same, and so when grouping /// Diagnostic error codes which actually are the same, and so when grouping
/// fixes we treat them the same. /// fixes we treat them the same.
static FIX_ALL_ERROR_CODES: Lazy<HashMap<&'static str, &'static str>> = static FIX_ALL_ERROR_CODES: Lazy<HashMap<&'static str, &'static str>> =
Lazy::new(|| { Lazy::new(|| ([("2339", "2339"), ("2345", "2339")]).into_iter().collect());
([("2339", "2339"), ("2345", "2339")])
.iter()
.cloned()
.collect()
});
/// Fixes which help determine if there is a preferred fix when there are /// Fixes which help determine if there is a preferred fix when there are
/// multiple fixes available. /// multiple fixes available.
@ -54,8 +49,7 @@ static PREFERRED_FIXES: Lazy<HashMap<&'static str, (u32, bool)>> =
("addMissingAwait", (1, false)), ("addMissingAwait", (1, false)),
("fixImport", (0, true)), ("fixImport", (0, true)),
]) ])
.iter() .into_iter()
.cloned()
.collect() .collect()
}); });

View file

@ -525,12 +525,10 @@ async fn generate_ts_diagnostics(
let specifiers = snapshot let specifiers = snapshot
.documents .documents
.documents(true, true) .documents(true, true)
.iter() .into_iter()
.map(|d| d.specifier().clone()) .map(|d| d.specifier().clone());
.collect::<Vec<_>>();
let (enabled_specifiers, disabled_specifiers) = specifiers let (enabled_specifiers, disabled_specifiers) = specifiers
.iter() .into_iter()
.cloned()
.partition::<Vec<_>, _>(|s| config.specifier_enabled(s)); .partition::<Vec<_>, _>(|s| config.specifier_enabled(s));
let ts_diagnostics_map: TsDiagnosticsMap = if !enabled_specifiers.is_empty() { let ts_diagnostics_map: TsDiagnosticsMap = if !enabled_specifiers.is_empty() {
let req = tsc::RequestMethod::GetDiagnostics(enabled_specifiers); let req = tsc::RequestMethod::GetDiagnostics(enabled_specifiers);

View file

@ -52,15 +52,13 @@ static JS_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
"content-type".to_string(), "content-type".to_string(),
"application/javascript".to_string(), "application/javascript".to_string(),
)]) )])
.iter() .into_iter()
.cloned()
.collect() .collect()
}); });
static JSX_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| { static JSX_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
([("content-type".to_string(), "text/jsx".to_string())]) ([("content-type".to_string(), "text/jsx".to_string())])
.iter() .into_iter()
.cloned()
.collect() .collect()
}); });
@ -69,15 +67,13 @@ static TS_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
"content-type".to_string(), "content-type".to_string(),
"application/typescript".to_string(), "application/typescript".to_string(),
)]) )])
.iter() .into_iter()
.cloned()
.collect() .collect()
}); });
static TSX_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| { static TSX_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
([("content-type".to_string(), "text/tsx".to_string())]) ([("content-type".to_string(), "text/tsx".to_string())])
.iter() .into_iter()
.cloned()
.collect() .collect()
}); });

View file

@ -538,7 +538,7 @@ pub async fn run_benchmarks_with_watch(
let paths_to_watch_clone = paths_to_watch.clone(); let paths_to_watch_clone = paths_to_watch.clone();
let files_changed = changed.is_some(); let files_changed = changed.is_some();
let bench_options = &bench_options; let bench_options = &bench_options;
let ps = ps.borrow(); let ps = ps.borrow().clone();
async move { async move {
let bench_modules = let bench_modules =
@ -617,7 +617,7 @@ pub async fn run_benchmarks_with_watch(
for path in changed.iter().filter_map(|path| { for path in changed.iter().filter_map(|path| {
deno_core::resolve_url_or_path(&path.to_string_lossy()).ok() deno_core::resolve_url_or_path(&path.to_string_lossy()).ok()
}) { }) {
if modules.contains(&&path) { if modules.contains(&path) {
modules_to_reload.push((specifier, ModuleKind::Esm)); modules_to_reload.push((specifier, ModuleKind::Esm));
break; break;
} }
@ -651,16 +651,15 @@ pub async fn run_benchmarks_with_watch(
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| { let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
let permissions = &permissions; let permissions = &permissions;
ps.borrow_mut().reset_for_file_watcher();
let ps = ps.borrow();
let bench_options = &bench_options; let bench_options = &bench_options;
ps.borrow_mut().reset_for_file_watcher();
let ps = ps.borrow().clone();
async move { async move {
let specifiers = let specifiers =
collect_specifiers(&bench_options.files, is_supported_bench_path)? collect_specifiers(&bench_options.files, is_supported_bench_path)?
.iter() .into_iter()
.filter(|specifier| contains_specifier(&modules_to_reload, specifier)) .filter(|specifier| contains_specifier(&modules_to_reload, specifier))
.cloned()
.collect::<Vec<ModuleSpecifier>>(); .collect::<Vec<ModuleSpecifier>>();
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?; check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;

View file

@ -987,7 +987,7 @@ pub async fn check_specifiers(
/// Test a collection of specifiers with test modes concurrently. /// Test a collection of specifiers with test modes concurrently.
async fn test_specifiers( async fn test_specifiers(
ps: ProcState, ps: &ProcState,
permissions: &Permissions, permissions: &Permissions,
specifiers_with_mode: Vec<(ModuleSpecifier, TestMode)>, specifiers_with_mode: Vec<(ModuleSpecifier, TestMode)>,
options: TestSpecifierOptions, options: TestSpecifierOptions,
@ -1328,7 +1328,7 @@ pub async fn run_tests(
} }
test_specifiers( test_specifiers(
ps, &ps,
&permissions, &permissions,
specifiers_with_mode, specifiers_with_mode,
TestSpecifierOptions { TestSpecifierOptions {
@ -1361,7 +1361,6 @@ pub async fn run_tests_with_watch(
let paths_to_watch_clone = paths_to_watch.clone(); let paths_to_watch_clone = paths_to_watch.clone();
let files_changed = changed.is_some(); let files_changed = changed.is_some();
let test_options = &test_options; let test_options = &test_options;
let ps = ps.borrow().clone(); let ps = ps.borrow().clone();
async move { async move {
@ -1445,7 +1444,7 @@ pub async fn run_tests_with_watch(
for path in changed.iter().filter_map(|path| { for path in changed.iter().filter_map(|path| {
deno_core::resolve_url_or_path(&path.to_string_lossy()).ok() deno_core::resolve_url_or_path(&path.to_string_lossy()).ok()
}) { }) {
if modules.contains(&&path) { if modules.contains(&path) {
modules_to_reload.push((specifier, ModuleKind::Esm)); modules_to_reload.push((specifier, ModuleKind::Esm));
break; break;
} }
@ -1490,11 +1489,10 @@ pub async fn run_tests_with_watch(
&test_options.doc, &test_options.doc,
) )
.await? .await?
.iter() .into_iter()
.filter(|(specifier, _)| { .filter(|(specifier, _)| {
contains_specifier(&modules_to_reload, specifier) contains_specifier(&modules_to_reload, specifier)
}) })
.cloned()
.collect::<Vec<(ModuleSpecifier, TestMode)>>(); .collect::<Vec<(ModuleSpecifier, TestMode)>>();
check_specifiers(&ps, permissions.clone(), specifiers_with_mode.clone()) check_specifiers(&ps, permissions.clone(), specifiers_with_mode.clone())
@ -1505,7 +1503,7 @@ pub async fn run_tests_with_watch(
} }
test_specifiers( test_specifiers(
ps, &ps,
permissions, permissions,
specifiers_with_mode, specifiers_with_mode,
TestSpecifierOptions { TestSpecifierOptions {

View file

@ -141,9 +141,9 @@ pub(crate) fn generate(
// Retain only *pure* parameters. // Retain only *pure* parameters.
let mut fast_fn_inputs = if optimizer.has_opstate_in_parameters() { let mut fast_fn_inputs = if optimizer.has_opstate_in_parameters() {
inputs.iter().skip(1).cloned().collect() inputs.into_iter().skip(1).collect()
} else { } else {
inputs.clone() inputs
}; };
let mut input_variants = optimizer let mut input_variants = optimizer