From b9a379093264da47368ea9665f685016fe35bfca Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 31 Mar 2023 18:12:14 +0530 Subject: perf: `const` op declaration (#18288) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Levente Kurusa Co-authored-by: Bartek IwaƄczuk --- ops/optimizer_tests/serde_v8_value.out | 55 ++++++++++++++++------------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'ops/optimizer_tests/serde_v8_value.out') diff --git a/ops/optimizer_tests/serde_v8_value.out b/ops/optimizer_tests/serde_v8_value.out index 2a10c00d4..d0f8dacdf 100644 --- a/ops/optimizer_tests/serde_v8_value.out +++ b/ops/optimizer_tests/serde_v8_value.out @@ -6,23 +6,37 @@ pub struct op_is_proxy; #[doc(hidden)] impl op_is_proxy { - pub fn name() -> &'static str { + pub const fn name() -> &'static str { stringify!(op_is_proxy) } - pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback { - use deno_core::v8::MapFnTo; - Self::v8_func.map_fn_to() + #[allow(clippy::not_unsafe_ptr_arg_deref)] + pub extern "C" fn v8_fn_ptr<'scope>( + info: *const deno_core::v8::FunctionCallbackInfo, + ) { + let info = unsafe { &*info }; + let scope = &mut unsafe { deno_core::v8::CallbackScope::new(info) }; + let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info( + info, + ); + let rv = deno_core::v8::ReturnValue::from_function_callback_info(info); + Self::v8_func(scope, args, rv); } - pub fn decl<'scope>() -> deno_core::OpDecl { + pub const fn decl<'scope>() -> deno_core::OpDecl { deno_core::OpDecl { name: Self::name(), - v8_fn_ptr: Self::v8_fn_ptr(), + v8_fn_ptr: Self::v8_fn_ptr as _, enabled: true, - fast_fn: Some( - Box::new(op_is_proxy_fast { - _phantom: ::std::marker::PhantomData, - }), - ), + fast_fn: { + use deno_core::v8::fast_api::Type::*; + use deno_core::v8::fast_api::CType; + Some( + deno_core::v8::fast_api::FastFunction::new( + &[V8Value, V8Value], + CType::Bool, + op_is_proxy_fast_fn as *const ::std::ffi::c_void, + ), + ) + }, is_async: false, is_unstable: false, is_v8: false, @@ -71,25 +85,6 @@ impl op_is_proxy { }; } } -struct op_is_proxy_fast { - _phantom: ::std::marker::PhantomData<()>, -} -impl<'scope> deno_core::v8::fast_api::FastFunction for op_is_proxy_fast { - #[inline(always)] - fn function(&self) -> *const ::std::ffi::c_void { - op_is_proxy_fast_fn as *const ::std::ffi::c_void - } - #[inline(always)] - fn args(&self) -> &'static [deno_core::v8::fast_api::Type] { - use deno_core::v8::fast_api::Type::*; - use deno_core::v8::fast_api::CType; - &[V8Value, V8Value] - } - #[inline(always)] - fn return_type(&self) -> deno_core::v8::fast_api::CType { - deno_core::v8::fast_api::CType::Bool - } -} #[allow(clippy::too_many_arguments)] fn op_is_proxy_fast_fn<'scope>( _: deno_core::v8::Local, -- cgit v1.2.3