emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/android e6186b6a2a4: Update Android port


From: Po Lu
Subject: feature/android e6186b6a2a4: Update Android port
Date: Mon, 13 Mar 2023 06:32:15 -0400 (EDT)

branch: feature/android
commit e6186b6a2a452f555ab024d1fc770683561ac024
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]