From 628452c70a8137d0a1062cf27e729d03989ac55d Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 21 Jun 2020 17:50:38 +0800 Subject: [PATCH] perf(napi-derive): remove useless alloc in function CallContext --- napi-derive/src/lib.rs | 6 +++--- napi/src/call_context.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/napi-derive/src/lib.rs b/napi-derive/src/lib.rs index fe647863..7ce7bfce 100644 --- a/napi-derive/src/lib.rs +++ b/napi-derive/src/lib.rs @@ -84,7 +84,7 @@ pub fn js_function(attr: TokenStream, input: TokenStream) -> TokenStream { use napi_rs::{Any, Env, Status, Value, CallContext}; let mut argc = #arg_len_span as usize; let mut raw_args = - unsafe { mem::MaybeUninit::<[napi_rs::sys::napi_value; 8]>::uninit().assume_init() }; + unsafe { mem::MaybeUninit::<[napi_rs::sys::napi_value; #arg_len_span as usize]>::uninit().assume_init() }; let mut raw_this = ptr::null_mut(); let mut has_error = false; @@ -94,7 +94,7 @@ pub fn js_function(attr: TokenStream, input: TokenStream) -> TokenStream { raw_env, cb_info, &mut argc as *mut usize as *mut u64, - &mut raw_args[0], + raw_args.as_mut_ptr(), &mut raw_this, ptr::null_mut(), ); @@ -102,7 +102,7 @@ pub fn js_function(attr: TokenStream, input: TokenStream) -> TokenStream { } let mut env = Env::from_raw(raw_env); - let call_ctx = CallContext::new(&mut env, raw_this, raw_args, #arg_len_span); + let call_ctx = CallContext::new(&mut env, raw_this, &raw_args, #arg_len_span); let result = call_ctx.and_then(|ctx| #new_fn_name(ctx)); has_error = has_error && result.is_err(); diff --git a/napi/src/call_context.rs b/napi/src/call_context.rs index 4a57daaf..69518c96 100644 --- a/napi/src/call_context.rs +++ b/napi/src/call_context.rs @@ -3,7 +3,7 @@ use crate::{sys, Any, Env, Error, Result, Status, Value, ValueType}; pub struct CallContext<'env, T: ValueType = Any> { pub env: &'env Env, pub this: Value, - args: [sys::napi_value; 8], + args: &'env [sys::napi_value], arg_len: usize, } @@ -12,7 +12,7 @@ impl<'env, T: ValueType> CallContext<'env, T> { pub fn new( env: &'env Env, this: sys::napi_value, - args: [sys::napi_value; 8], + args: &'env [sys::napi_value], arg_len: usize, ) -> Result { Ok(Self {