From 9ee5fe8d6b8de82d871b584b656fa4b0e4b8a280 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 22 Oct 2023 06:02:36 +0900 Subject: [PATCH] =?UTF-8?q?`JavaStr`=E3=81=AE=E5=86=85=E5=AE=B9=E3=82=92?= =?UTF-8?q?=E7=9B=B4=E3=81=ABUTF-8=E3=81=A8=E3=81=97=E3=81=A6=E8=AA=AD?= =?UTF-8?q?=E3=81=BE=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voicevox_core_java_api/src/open_jtalk.rs | 7 +++++-- .../voicevox_core_java_api/src/user_dict.rs | 21 +++++++++++-------- .../voicevox_core_java_api/src/voice_model.rs | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/voicevox_core_java_api/src/open_jtalk.rs b/crates/voicevox_core_java_api/src/open_jtalk.rs index 98feaacb0..f26128d35 100644 --- a/crates/voicevox_core_java_api/src/open_jtalk.rs +++ b/crates/voicevox_core_java_api/src/open_jtalk.rs @@ -1,4 +1,7 @@ -use std::sync::{Arc, Mutex}; +use std::{ + borrow::Cow, + sync::{Arc, Mutex}, +}; use crate::common::throw_if_err; use jni::{ @@ -26,7 +29,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_OpenJtalk_rsNewWithInit ) { throw_if_err(env, (), |env| { let open_jtalk_dict_dir = env.get_string(&open_jtalk_dict_dir)?; - let open_jtalk_dict_dir = open_jtalk_dict_dir.to_str()?; + let open_jtalk_dict_dir = &*Cow::from(&open_jtalk_dict_dir); let internal = voicevox_core::OpenJtalk::new_with_initialize(open_jtalk_dict_dir)?; env.set_rust_field(&this, "handle", Arc::new(internal))?; diff --git a/crates/voicevox_core_java_api/src/user_dict.rs b/crates/voicevox_core_java_api/src/user_dict.rs index 4f7bc78d8..f5a79d854 100644 --- a/crates/voicevox_core_java_api/src/user_dict.rs +++ b/crates/voicevox_core_java_api/src/user_dict.rs @@ -1,5 +1,8 @@ use jni::objects::JClass; -use std::sync::{Arc, Mutex}; +use std::{ + borrow::Cow, + sync::{Arc, Mutex}, +}; use crate::common::throw_if_err; use jni::{ @@ -34,7 +37,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsAddWord<'loc .clone(); let word_json = env.get_string(&word_json)?; - let word_json = word_json.to_str()?; + let word_json = &Cow::from(&word_json); let word: voicevox_core::UserDictWord = serde_json::from_str(word_json)?; @@ -63,9 +66,9 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsUpdateWord<' .clone(); let uuid = env.get_string(&uuid)?; - let uuid = uuid.to_str()?.parse()?; + let uuid = Cow::from(&uuid).parse()?; let word_json = env.get_string(&word_json)?; - let word_json = word_json.to_str()?; + let word_json = &Cow::from(&word_json); let word: voicevox_core::UserDictWord = serde_json::from_str(word_json)?; @@ -90,7 +93,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsRemoveWord<' .clone(); let uuid = env.get_string(&uuid)?; - let uuid = uuid.to_str()?.parse()?; + let uuid = Cow::from(&uuid).parse()?; { let mut internal = internal.lock().unwrap(); @@ -137,7 +140,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsLoad<'local> .clone(); let path = env.get_string(&path)?; - let path = path.to_str()?; + let path = &Cow::from(&path); { let mut internal = internal.lock().unwrap(); @@ -160,7 +163,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsSave<'local> .clone(); let path = env.get_string(&path)?; - let path = path.to_str()?; + let path = &Cow::from(&path); { let internal = internal.lock().unwrap(); @@ -211,7 +214,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsToZenkaku<'local>( ) -> jobject { throw_if_err(env, std::ptr::null_mut(), |env| { let text = env.get_string(&text)?; - let text = text.to_str()?; + let text = &Cow::from(&text); let text = voicevox_core::__internal::to_zenkaku(text); @@ -228,7 +231,7 @@ extern "system" fn Java_jp_hiroshiba_voicevoxcore_UserDict_rsValidatePronunciati ) { throw_if_err(env, (), |env| { let text = env.get_string(&text)?; - let text = text.to_str()?; + let text = &Cow::from(&text); voicevox_core::__internal::validate_pronunciation(text)?; diff --git a/crates/voicevox_core_java_api/src/voice_model.rs b/crates/voicevox_core_java_api/src/voice_model.rs index 33ae01288..c1cdb462c 100644 --- a/crates/voicevox_core_java_api/src/voice_model.rs +++ b/crates/voicevox_core_java_api/src/voice_model.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{borrow::Cow, sync::Arc}; use crate::common::{throw_if_err, RUNTIME}; use jni::{ @@ -15,7 +15,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_VoiceModel_rsFromPath<' ) { throw_if_err(env, (), |env| { let model_path = env.get_string(&model_path)?; - let model_path = model_path.to_str()?; + let model_path = &*Cow::from(&model_path); let internal = RUNTIME.block_on(voicevox_core::VoiceModel::from_path(model_path))?;