From a561cc28cd59b51846fce9a9de598e2fd6e9b54e Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Tue, 21 Mar 2023 12:13:32 -0600 Subject: chore(cli) Use with_context(|| format!(...)) rather than context(format!(...)) to avoid allocations in non-error path (#18332) --- cli/args/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cli') diff --git a/cli/args/mod.rs b/cli/args/mod.rs index a624dcc79..848f50eb4 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -669,9 +669,9 @@ impl CliOptions { file_fetcher, ) .await - .context(format!( - "Unable to load '{import_map_specifier}' import map" - )) + .with_context(|| { + format!("Unable to load '{import_map_specifier}' import map") + }) .map(Some) } @@ -1091,7 +1091,9 @@ fn resolve_import_map_specifier( } let specifier = deno_core::resolve_url_or_path(import_map_path, current_dir) - .context(format!("Bad URL (\"{import_map_path}\") for import map."))?; + .with_context(|| { + format!("Bad URL (\"{import_map_path}\") for import map.") + })?; return Ok(Some(specifier)); } else if let Some(config_file) = &maybe_config_file { // if the config file is an import map we prefer to use it, over `importMap` @@ -1131,7 +1133,7 @@ fn resolve_import_map_specifier( // use "import resolution" with the config file as the base. } else { deno_core::resolve_import(&import_map_path, config_file.specifier.as_str()) - .context(format!( + .with_context(|| format!( "Bad URL (\"{import_map_path}\") for import map." ))? }; -- cgit v1.2.3