Remove unnecessary Box roundtrip in Dialog accessors

master
Lonami Exo 2022-10-13 17:06:23 +02:00
parent e1985e8c73
commit f2cd0eb69a
1 changed files with 3 additions and 3 deletions

View File

@ -181,7 +181,7 @@ pub unsafe extern "C" fn Java_dev_lonami_talaria_bindings_Native_dialogCount(
_: JObject,
dialogs_ptr: jlong,
) -> jint {
let dialogs = Box::leak(Box::from_raw(dialogs_ptr as *mut Vec<Dialog>));
let dialogs = &mut *(dialogs_ptr as *mut Vec<Dialog>);
dialogs.len() as jint
}
@ -192,7 +192,7 @@ pub unsafe extern "C" fn Java_dev_lonami_talaria_bindings_Native_dialogPacked(
dialogs_ptr: jlong,
index: jint,
) -> jstring {
let dialogs = Box::leak(Box::from_raw(dialogs_ptr as *mut Vec<Dialog>));
let dialogs = &mut *(dialogs_ptr as *mut Vec<Dialog>);
let packed = dialogs[index as usize].chat().pack().to_hex();
let output = env.new_string(packed).unwrap();
@ -206,7 +206,7 @@ pub unsafe extern "C" fn Java_dev_lonami_talaria_bindings_Native_dialogTitle(
dialogs_ptr: jlong,
index: jint,
) -> jstring {
let dialogs = Box::leak(Box::from_raw(dialogs_ptr as *mut Vec<Dialog>));
let dialogs = &mut *(dialogs_ptr as *mut Vec<Dialog>);
let title = dialogs[index as usize].chat().name();
let output = env.new_string(title).unwrap();