1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore(cli) Use with_context(|| format!(...)) rather than context(format!(...)) to avoid allocations in non-error path (#18332)

This commit is contained in:
Matt Mastracci 2023-03-21 12:13:32 -06:00 committed by GitHub
parent 0d27de943a
commit a561cc28cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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."
))?
};