From e4a245248cfe46a24d6fd2593ab70f4da078d946 Mon Sep 17 00:00:00 2001 From: zhangyuang Date: Sun, 17 Nov 2024 21:06:27 +0800 Subject: [PATCH] chore: code optimize --- src/datatype/function.rs | 10 ++-------- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/datatype/function.rs b/src/datatype/function.rs index 636b3c6..fc910ce 100644 --- a/src/datatype/function.rs +++ b/src/datatype/function.rs @@ -20,19 +20,13 @@ pub unsafe fn get_rs_value_from_pointer( RsArgsValue::I32(number) => { let data = match number.to_basic_data_type() { BasicDataType::U8 => RsArgsValue::U8(*(pointer as *mut u8)), - BasicDataType::I32 => { - return RsArgsValue::I32(*(pointer as *mut i32)); - } + BasicDataType::I32 => RsArgsValue::I32(*(pointer as *mut i32)), BasicDataType::I64 => RsArgsValue::I64(*(pointer as *mut i64)), BasicDataType::BigInt => RsArgsValue::BigInt(*(pointer as *mut i64)), BasicDataType::U64 => RsArgsValue::U64(*(pointer as *mut u64)), BasicDataType::Float => RsArgsValue::Float(*(pointer as *mut f32)), BasicDataType::Double => RsArgsValue::Double(*(pointer as *mut f64)), - BasicDataType::Boolean => RsArgsValue::Boolean(if *(pointer as *mut i32) == 0 { - false - } else { - true - }), + BasicDataType::Boolean => RsArgsValue::Boolean(!*(pointer as *mut i32) == 0), BasicDataType::String => { RsArgsValue::String(create_c_string_from_ptr(*(pointer as *mut *mut c_char))) } diff --git a/src/lib.rs b/src/lib.rs index 24786e3..b091bc6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -265,7 +265,7 @@ unsafe fn load(env: Env, params: FFIParams) -> napi::Result { let struct_type_ptr = Box::into_raw(Box::new(struct_type_box)); ffi_type_cleanup.elements_box = Some(elements_ptr); ffi_type_cleanup.struct_type_box = Some(struct_type_ptr); - struct_type_ptr as *mut ffi_type + struct_type_ptr } else { &mut ffi_type_pointer as *mut ffi_type }