[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ad011fd3ac: Make STRING_SET_MULTIBYTE an inline function
From: |
Stefan Monnier |
Subject: |
master ad011fd3ac: Make STRING_SET_MULTIBYTE an inline function |
Date: |
Sat, 9 Jul 2022 12:53:39 -0400 (EDT) |
branch: master
commit ad011fd3accd97f5ab96dd7459ee8ef9f6ab4090
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
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.
---
src/composite.c | 10 ++++++----
src/lisp.h | 14 +++++++-------
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/composite.c b/src/composite.c
index 4d69702171..552214ae84 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 5ffc2bb038..dc496cc165 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. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master ad011fd3ac: Make STRING_SET_MULTIBYTE an inline function,
Stefan Monnier <=