mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
perf: lazy bootstrap options - first pass (#21164)
Move most runtime options to be lazily loaded. Constant options will be covered in a different PR. Towards https://github.com/denoland/deno/issues/21133
This commit is contained in:
parent
39223f709b
commit
1ef617e8f3
10 changed files with 139 additions and 149 deletions
61
runtime/ops/bootstrap.rs
Normal file
61
runtime/ops/bootstrap.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::op2;
|
||||
use deno_core::OpState;
|
||||
|
||||
use crate::BootstrapOptions;
|
||||
|
||||
deno_core::extension!(
|
||||
deno_bootstrap,
|
||||
ops = [
|
||||
op_bootstrap_args,
|
||||
op_bootstrap_pid,
|
||||
op_bootstrap_numcpus,
|
||||
op_bootstrap_user_agent,
|
||||
op_bootstrap_language,
|
||||
op_bootstrap_log_level,
|
||||
op_bootstrap_no_color,
|
||||
],
|
||||
);
|
||||
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_bootstrap_args(state: &mut OpState) -> Vec<String> {
|
||||
state.borrow::<BootstrapOptions>().args.clone()
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
#[smi]
|
||||
pub fn op_bootstrap_pid() -> u32 {
|
||||
std::process::id()
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
#[smi]
|
||||
pub fn op_bootstrap_numcpus(state: &mut OpState) -> u32 {
|
||||
state.borrow::<BootstrapOptions>().cpu_count as u32
|
||||
}
|
||||
|
||||
#[op2]
|
||||
#[string]
|
||||
pub fn op_bootstrap_user_agent(state: &mut OpState) -> String {
|
||||
state.borrow::<BootstrapOptions>().user_agent.clone()
|
||||
}
|
||||
|
||||
#[op2]
|
||||
#[string]
|
||||
pub fn op_bootstrap_language(state: &mut OpState) -> String {
|
||||
state.borrow::<BootstrapOptions>().locale.clone()
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
#[smi]
|
||||
pub fn op_bootstrap_log_level(state: &mut OpState) -> i32 {
|
||||
state.borrow::<BootstrapOptions>().log_level as i32
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_bootstrap_no_color(state: &mut OpState) -> bool {
|
||||
let options = state.borrow::<BootstrapOptions>();
|
||||
options.no_color || !options.is_tty
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue