]> git.eshelyaron.com Git - emacs.git/commitdiff
Make STRING_SET_MULTIBYTE an inline function
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 9 Jul 2022 16:53:34 +0000 (12:53 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sat, 9 Jul 2022 16:53:34 +0000 (12:53 -0400)
* src/lisp.h (STRING_SET_MULTIBYTE): Make it into a function.

* src/composite.c (Fcomposition_get_gstring):
Prefer `make_multibyte_string` over Fconcat+STRING_SET_MULTIBYTE.

src/composite.c
src/lisp.h

index 4d69702171f4768f8e99a988f1668385ad19c4e1..552214ae848e8c8029d90fa606376dd55c91d781 100644 (file)
@@ -1871,7 +1871,8 @@ should be ignored.  */)
   else
     {
       CHECK_STRING (string);
-      validate_subarray (string, from, to, SCHARS (string), &frompos, &topos);
+      ptrdiff_t chars = SCHARS (string);
+      validate_subarray (string, from, to, chars, &frompos, &topos);
       if (! STRING_MULTIBYTE (string))
        {
          ptrdiff_t i;
@@ -1881,9 +1882,10 @@ should be ignored.  */)
              error ("Attempt to shape unibyte text");
          /* STRING is a pure-ASCII string, so we can convert it (or,
             rather, its copy) to multibyte and use that thereafter.  */
-         Lisp_Object string_copy = Fconcat (1, &string);
-         STRING_SET_MULTIBYTE (string_copy);
-         string = string_copy;
+         /* FIXME: Not clear why we need to do that: AFAICT the rest of
+             the code should work on an ASCII-only unibyte string just
+             as well (bug#56347).  */
+         string = make_multibyte_string (SDATA (string), chars, chars);
        }
       frombyte = string_char_to_byte (string, frompos);
     }
index 5ffc2bb0386894d3d5e581f76b3bcdfcf9e00046..dc496cc16588439406e55a3f481beff969a737c5 100644 (file)
@@ -1640,13 +1640,13 @@ STRING_MULTIBYTE (Lisp_Object str)
 
 /* Mark STR as a multibyte string.  Assure that STR contains only
    ASCII characters in advance.  */
-#define STRING_SET_MULTIBYTE(STR)                      \
-  do {                                                 \
-    if (XSTRING (STR)->u.s.size == 0)                  \
-      (STR) = empty_multibyte_string;                  \
-    else                                               \
-      XSTRING (STR)->u.s.size_byte = XSTRING (STR)->u.s.size; \
-  } while (false)
+INLINE void
+STRING_SET_MULTIBYTE (Lisp_Object str)
+{
+  /* The 0-length strings are unique&shared so we can't modify them.  */
+  eassert (XSTRING (str)->u.s.size > 0);
+  XSTRING (str)->u.s.size_byte = XSTRING (str)->u.s.size;
+}
 
 /* Convenience functions for dealing with Lisp strings.  */