diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-03-31 18:12:14 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 14:42:14 +0200 |
commit | b9a379093264da47368ea9665f685016fe35bfca (patch) | |
tree | af6fd2e56846b8d0a6d1d8d88c0bfcffbb34c4d6 /ops/lib.rs | |
parent | 0f41aff1d9f6c131ff69d6dd1dc053afb008a19d (diff) |
perf: `const` op declaration (#18288)
Co-authored-by: Levente Kurusa <lkurusa@kernelstuff.org>
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ops/lib.rs')
-rw-r--r-- | ops/lib.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/ops/lib.rs b/ops/lib.rs index bd87bc492..aee6c8c03 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -184,19 +184,23 @@ impl Op { #[doc(hidden)] impl #name { - pub fn name() -> &'static str { + pub const fn name() -> &'static str { stringify!(#name) } - pub fn v8_fn_ptr #generics () -> #core::v8::FunctionCallback #where_clause { - use #core::v8::MapFnTo; - Self::v8_func::<#type_params>.map_fn_to() + #[allow(clippy::not_unsafe_ptr_arg_deref)] + pub extern "C" fn v8_fn_ptr #generics (info: *const #core::v8::FunctionCallbackInfo) #where_clause { + let info = unsafe { &*info }; + let scope = &mut unsafe { #core::v8::CallbackScope::new(info) }; + let args = #core::v8::FunctionCallbackArguments::from_function_callback_info(info); + let rv = #core::v8::ReturnValue::from_function_callback_info(info); + Self::v8_func::<#type_params>(scope, args, rv); } - pub fn decl #generics () -> #core::OpDecl #where_clause { + pub const fn decl #generics () -> #core::OpDecl #where_clause { #core::OpDecl { name: Self::name(), - v8_fn_ptr: Self::v8_fn_ptr::<#type_params>(), + v8_fn_ptr: Self::v8_fn_ptr::<#type_params> as _, enabled: true, fast_fn: #decl, is_async: #is_async, |