mirror of
https://github.com/rust-mobile/android-activity.git
synced 2026-07-04 05:47:26 +00:00
Replace cesu8 with simd_cesu8 (consistent with jni 0.22.2)
The `cesu8` crate hasn't been updated for 10 years where as the `simd_cesu8` crate is more actively maintained and is expected to have better performance in all conditions: <https://docs.rs/simd_cesu8/latest/simd_cesu8/#benchmarks> This change is consistent with the `jni` crate which switched to using `simd_cesu8` in the 0.22.2 release - so this avoids needing to build two separate crates for mutf8 encoding. This also addresses the current CI issue that comes from incorrectly depending on `cesu8 = "1"` instead of `"1.1.0"` (which adds the java/mutf8 APIs that we used). Previously this went unnoticed because of the `jni` crate pulling in the correct minimum version.
This commit is contained in:
@@ -21,14 +21,14 @@ rust-version = "1.85.0"
|
||||
# In general it's only the final application crate that needs
|
||||
# to decide on a backend.
|
||||
default = []
|
||||
game-activity = []
|
||||
game-activity = ["simd_cesu8"]
|
||||
native-activity = []
|
||||
api-level-30 = ["ndk/api-level-30"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
cesu8 = "1"
|
||||
jni = "0.22"
|
||||
simd_cesu8 = { version = "1.0.1", optional = true }
|
||||
jni = "0.22.2"
|
||||
ndk-sys = "0.6.0"
|
||||
ndk = { version = "0.9.0", default-features = false }
|
||||
ndk-context = "0.1.1"
|
||||
|
||||
@@ -216,7 +216,7 @@ impl NativeAppGlue {
|
||||
pub fn set_text_input_state(&self, state: TextInputState) {
|
||||
unsafe {
|
||||
let activity = (*self.as_ptr()).activity;
|
||||
let modified_utf8 = cesu8::to_java_cesu8(&state.text);
|
||||
let modified_utf8 = simd_cesu8::mutf8::encode(&state.text);
|
||||
let text_length = modified_utf8.len() as i32;
|
||||
let modified_utf8_bytes = modified_utf8.as_ptr();
|
||||
let ffi_state = ffi::GameTextInputState {
|
||||
@@ -525,7 +525,7 @@ impl AndroidAppInner {
|
||||
let text_modified_utf8: *const u8 = (*state).text_UTF8.cast();
|
||||
let text_modified_utf8 =
|
||||
std::slice::from_raw_parts(text_modified_utf8, (*state).text_length as usize);
|
||||
match cesu8::from_java_cesu8(text_modified_utf8) {
|
||||
match simd_cesu8::mutf8::decode(text_modified_utf8) {
|
||||
Ok(str) => {
|
||||
let len = str.len();
|
||||
(*out_ptr).text = String::from(str);
|
||||
|
||||
Reference in New Issue
Block a user