diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-03-17 16:15:27 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-17 22:15:27 +0000 |
commit | 3487fde236d0852a8b0672c293fa41a741f471e8 (patch) | |
tree | af466368147a08b787080446319a3a46a60ee37d /cli/tsc | |
parent | e55b448730160a6e4df9815a268d4049ac89deab (diff) |
perf(core) Reduce copying and cloning in extension initialization (#18252)
Follow-up to #18210:
* we are passing the generated `cfg` object into the state function
rather than passing individual config fields
* reduce cloning dramatically by making the state_fn `FnOnce`
* `take` for `ExtensionBuilder` to avoid more unnecessary copies
* renamed `config` to `options`
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/mod.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 387fd3aa1..45589780f 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -41,7 +41,6 @@ use std::collections::HashMap; use std::fmt; use std::path::Path; use std::path::PathBuf; -use std::rc::Rc; use std::sync::Arc; mod diagnostics; @@ -829,19 +828,19 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { deno_core::extension!(deno_cli_tsc, ops_fn = deno_ops, - config = { - request: Rc<Request>, + options = { + request: Request, root_map: HashMap<String, Url>, remapped_specifiers: HashMap<String, Url>, }, - state = |state, request, root_map, remapped_specifiers| { + state = |state, options| { state.put(State::new( - request.graph.clone(), - request.hash_data.clone(), - request.maybe_npm_resolver.clone(), - request.maybe_tsbuildinfo.clone(), - root_map, - remapped_specifiers, + options.request.graph, + options.request.hash_data, + options.request.maybe_npm_resolver, + options.request.maybe_tsbuildinfo, + options.root_map, + options.remapped_specifiers, std::env::current_dir() .context("Unable to get CWD") .unwrap(), @@ -861,7 +860,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(compiler_snapshot()), extensions: vec![deno_cli_tsc::init_ops( - Rc::new(request), + request, root_map, remapped_specifiers, )], |