1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 08:39:09 -05:00
denoland-deno/ops/op2/test_cases/sync/smi.out
Matt Mastracci 8fe9b8a4cc
refactor(ops): ops2 supports result in fast path (#19603)
Implements `Result` in fast-calls. Note that the approach here is
slightly different. Rather than store the last result in the `OpState`,
we put it into the `OpCtx` which saves us a lookup and lock in the error
case. We do not have to lock this field as it's guaranteed only one
runtime and thread can ever access it.

The fastcall path for many ops can avoid doing a great deal of work,
even for `Result` return values. In the previous iteration of `ops`, all
`Result`-returning functions would fetch and lock the `OpState`,
regardless of whether it was used or not.
2023-06-25 16:36:09 +02:00

51 lines
1.7 KiB
Text

#[allow(non_camel_case_types)]
struct op_add {}
impl op_add {
pub const fn name() -> &'static str {
stringify!(op_add)
}
pub const fn decl() -> deno_core::_ops::OpDecl {
deno_core::_ops::OpDecl {
name: stringify!(op_add),
v8_fn_ptr: Self::slow_function as _,
enabled: true,
fast_fn: Some({
use deno_core::v8::fast_api::Type;
use deno_core::v8::fast_api::CType;
deno_core::v8::fast_api::FastFunction::new(
&[Type::V8Value, Type::Int32, Type::Uint32],
CType::Uint32,
Self::fast_function as *const ::std::ffi::c_void,
)
}),
is_async: false,
is_unstable: false,
is_v8: false,
arg_count: 2usize as u8,
}
}
pub extern "C" fn slow_function(info: *const deno_core::v8::FunctionCallbackInfo) {
let mut rv = deno_core::v8::ReturnValue::from_function_callback_info(unsafe {
&*info
});
let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe {
&*info
});
let arg0 = args.get(0usize as i32);
let arg0 = deno_core::_ops::to_i32(&arg0) as _;
let arg1 = args.get(1usize as i32);
let arg1 = deno_core::_ops::to_u32(&arg1) as _;
let result = Self::call(arg0, arg1);
rv.set_uint32(result as u32);
}
fn fast_function(
_: deno_core::v8::Local<deno_core::v8::Object>,
arg0: i32,
arg1: u32,
) -> u32 {
let result = Self::call(arg0 as _, arg1 as _);
result
}
#[inline(always)]
fn call(id: ResourceId, extra: u16) -> u32 {}
}