1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 07:39:15 -05:00
denoland-deno/cli/ops/mod.rs
Matt Mastracci 3487fde236
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`
2023-03-17 22:15:27 +00:00

30 lines
686 B
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::proc_state::ProcState;
use deno_core::error::AnyError;
use deno_core::op;
use deno_core::Extension;
use deno_core::OpState;
pub mod bench;
pub mod testing;
pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
vec![deno_cli::init_ops(ps)]
}
deno_core::extension!(deno_cli,
ops = [op_npm_process_state],
options = {
ps: ProcState,
},
state = |state, options| {
state.put(options.ps);
},
);
#[op]
fn op_npm_process_state(state: &mut OpState) -> Result<String, AnyError> {
let proc_state = state.borrow_mut::<ProcState>();
Ok(proc_state.npm_resolver.get_npm_process_state())
}