summaryrefslogtreecommitdiff
path: root/cli/tsc/mod.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-04-04 06:46:31 -0600
committerGitHub <noreply@github.com>2023-04-04 06:46:31 -0600
commita1764f7690cfdc3e42724fcad29ef954b7e576a4 (patch)
tree1b621ebd7a6ef50687eeb2061740895096136e8a /cli/tsc/mod.rs
parent2dc20168371e827b86e2ce0d1d7787139fba68f3 (diff)
refactor(core): Improve ergonomics of managing ASCII strings (#18498)
This is a follow-on to the earlier work in reducing string copies, mainly focused on ensuring that ASCII strings are easy to provide to the JS runtime. While we are replacing a 16-byte reference in a number of places with a 24-byte structure (measured via `std::mem::size_of`), the reduction in copies wins out over the additional size of the arguments passed into functions. Benchmarking shows approximately the same if not slightly less wallclock time/instructions retired, but I believe this continues to open up further refactoring opportunities.
Diffstat (limited to 'cli/tsc/mod.rs')
-rw-r--r--cli/tsc/mod.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs
index a9dc5b7f3..3bd8efefa 100644
--- a/cli/tsc/mod.rs
+++ b/cli/tsc/mod.rs
@@ -13,6 +13,7 @@ use crate::util::path::mapped_specifier_for_tsc;
use deno_ast::MediaType;
use deno_core::anyhow::anyhow;
use deno_core::anyhow::Context;
+use deno_core::ascii_str;
use deno_core::error::AnyError;
use deno_core::located_script_name;
use deno_core::op;
@@ -131,8 +132,8 @@ fn get_asset_texts_from_new_runtime() -> Result<Vec<AssetText>, AnyError> {
extensions: vec![deno_cli_tsc::init_ops()],
..Default::default()
});
- let global =
- runtime.execute_script("get_assets.js", "globalThis.getAssets()")?;
+ let global = runtime
+ .execute_script("get_assets.js", ascii_str!("globalThis.getAssets()"))?;
let scope = &mut runtime.handle_scope();
let local = deno_core::v8::Local::new(scope, global);
Ok(serde_v8::from_v8::<Vec<AssetText>>(scope, local)?)
@@ -792,15 +793,14 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
},
);
- let startup_source = "globalThis.startup({ legacyFlag: false })";
+ let startup_source = ascii_str!("globalThis.startup({ legacyFlag: false })");
let request_value = json!({
"config": request.config,
"debug": request.debug,
"rootNames": root_names,
"localOnly": request.check_mode == TypeCheckMode::Local,
});
- let request_str = request_value.to_string();
- let exec_source = format!("globalThis.exec({request_str})");
+ let exec_source = format!("globalThis.exec({request_value})").into();
let mut runtime = JsRuntime::new(RuntimeOptions {
startup_snapshot: Some(compiler_snapshot()),
@@ -974,7 +974,7 @@ mod tests {
..Default::default()
});
js_runtime
- .execute_script(
+ .execute_script_static(
"<anon>",
r#"
if (!(startup)) {