Remove unnecessary Box roundtrip in Dialog accessors

This commit is contained in:
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, _: JObject,
dialogs_ptr: jlong, dialogs_ptr: jlong,
) -> jint { ) -> 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 dialogs.len() as jint
} }
@ -192,7 +192,7 @@ pub unsafe extern "C" fn Java_dev_lonami_talaria_bindings_Native_dialogPacked(
dialogs_ptr: jlong, dialogs_ptr: jlong,
index: jint, index: jint,
) -> jstring { ) -> 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 packed = dialogs[index as usize].chat().pack().to_hex();
let output = env.new_string(packed).unwrap(); 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, dialogs_ptr: jlong,
index: jint, index: jint,
) -> jstring { ) -> 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 title = dialogs[index as usize].chat().name();
let output = env.new_string(title).unwrap(); let output = env.new_string(title).unwrap();