Skip to content

Commit

Permalink
chore: code optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Nov 17, 2024
1 parent 2cd1def commit e4a2452
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/datatype/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ unsafe fn load(env: Env, params: FFIParams) -> napi::Result<JsUnknown> {
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
}
Expand Down

0 comments on commit e4a2452

Please sign in to comment.