From e6186b6a2a452f555ab024d1fc770683561ac024 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 13 Mar 2023 18:31:30 +0800 Subject: [PATCH] Update Android port * src/android.c (android_check_string, android_build_string): Reduce consing when building menu bar strings. --- src/android.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/android.c b/src/android.c index 16c645ced1e..efbf8fc95cc 100644 --- a/src/android.c +++ b/src/android.c @@ -5389,6 +5389,23 @@ emacs_abort (void) +/* Return whether or not TEXT, a string without multibyte + characters, has no bytes with the 8th bit set. */ + +static bool +android_check_string (Lisp_Object text) +{ + ptrdiff_t i; + + for (i = 0; i < ASIZE (text); ++i) + { + if (SREF (text, i) & 128) + return false; + } + + return true; +} + /* Given a Lisp string TEXT, return a local reference to an equivalent Java string. */ @@ -5401,6 +5418,21 @@ android_build_string (Lisp_Object text) jchar *characters; USE_SAFE_ALLOCA; + /* Directly encode TEXT if it contains no multibyte + characters. This is okay because the Java extended UTF + format is compatible with ASCII. */ + + if (SBYTES (text) == SCHARS (text) + && android_check_string (text)) + { + string = (*android_java_env)->NewStringUTF (android_java_env, + SSDATA (text)); + android_exception_check (); + SAFE_FREE (); + + return string; + } + encoded = code_convert_string_norecord (text, Qutf_16le, true); nchars = (SBYTES (encoded) / sizeof (jchar)); -- 2.39.2