Merge pull request #79 from napi-rs/remove-useless-alloc
perf(napi-derive): remove useless alloc in function CallContext
This commit is contained in:
commit
17cc813295
2 changed files with 5 additions and 5 deletions
|
@ -84,7 +84,7 @@ pub fn js_function(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
use napi_rs::{Any, Env, Status, Value, CallContext};
|
use napi_rs::{Any, Env, Status, Value, CallContext};
|
||||||
let mut argc = #arg_len_span as usize;
|
let mut argc = #arg_len_span as usize;
|
||||||
let mut raw_args =
|
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 raw_this = ptr::null_mut();
|
||||||
|
|
||||||
let mut has_error = false;
|
let mut has_error = false;
|
||||||
|
@ -94,7 +94,7 @@ pub fn js_function(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
raw_env,
|
raw_env,
|
||||||
cb_info,
|
cb_info,
|
||||||
&mut argc as *mut usize as *mut u64,
|
&mut argc as *mut usize as *mut u64,
|
||||||
&mut raw_args[0],
|
raw_args.as_mut_ptr(),
|
||||||
&mut raw_this,
|
&mut raw_this,
|
||||||
ptr::null_mut(),
|
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 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));
|
let result = call_ctx.and_then(|ctx| #new_fn_name(ctx));
|
||||||
has_error = has_error && result.is_err();
|
has_error = has_error && result.is_err();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{sys, Any, Env, Error, Result, Status, Value, ValueType};
|
||||||
pub struct CallContext<'env, T: ValueType = Any> {
|
pub struct CallContext<'env, T: ValueType = Any> {
|
||||||
pub env: &'env Env,
|
pub env: &'env Env,
|
||||||
pub this: Value<T>,
|
pub this: Value<T>,
|
||||||
args: [sys::napi_value; 8],
|
args: &'env [sys::napi_value],
|
||||||
arg_len: usize,
|
arg_len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ impl<'env, T: ValueType> CallContext<'env, T> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
env: &'env Env,
|
env: &'env Env,
|
||||||
this: sys::napi_value,
|
this: sys::napi_value,
|
||||||
args: [sys::napi_value; 8],
|
args: &'env [sys::napi_value],
|
||||||
arg_len: usize,
|
arg_len: usize,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
Loading…
Reference in a new issue