From: Stefan Monnier Date: Sat, 9 Jul 2022 16:53:34 +0000 (-0400) Subject: Make STRING_SET_MULTIBYTE an inline function X-Git-Tag: emacs-29.0.90~1447^2~1059 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ad011fd3accd97f5ab96dd7459ee8ef9f6ab4090;p=emacs.git Make STRING_SET_MULTIBYTE an inline function * 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. --- diff --git a/src/composite.c b/src/composite.c index 4d69702171f..552214ae848 100644 --- a/src/composite.c +++ b/src/composite.c @@ -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); } diff --git a/src/lisp.h b/src/lisp.h index 5ffc2bb0386..dc496cc1658 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -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. */