diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2022-07-11 10:34:40 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2022-07-11 10:38:49 +0200 |
commit | 69b68099ecfb053ac77e0a954ab7467c440321ff (patch) | |
tree | 57f810ec7d6addf847ca4b1c70ff5d0cf5d02e21 /src/fns.c | |
parent | 96846877930f580e122e9af85b4653918c542f89 (diff) | |
download | emacs-69b68099ecfb053ac77e0a954ab7467c440321ff.tar.gz |
Simplify and speed up string-to-multibyte
* src/character.h (str_to_multibyte):
* src/character.c (str_to_multibyte): Change signature and simplify;
the conversion is no longer done in-place.
* src/fns.c (string_to_multibyte): Drop temporary buffer and memcpy;
adapt to new str_to_multibyte signature.
* src/print.c (print_string): Drop memcpy; adapt call to str_to_multibyte.
* test/src/fns-tests.el (fns--string-to-unibyte): Rename to...
(fns--string-to-unibyte-multibyte): ... this and strengthen, so that
the test covers string-to-multibyte reasonably well.
Diffstat (limited to 'src/fns.c')
-rw-r--r-- | src/fns.c | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/fns.c b/src/fns.c index 61ed01eee4e..7d8f957ef98 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1237,33 +1237,24 @@ string_make_multibyte (Lisp_Object string) /* Convert STRING (if unibyte) to a multibyte string without changing - the number of characters. Characters 0200 through 0237 are - converted to eight-bit characters. */ + the number of characters. Characters 0x80..0xff are interpreted as + raw bytes. */ Lisp_Object string_to_multibyte (Lisp_Object string) { - unsigned char *buf; - ptrdiff_t nbytes; - Lisp_Object ret; - USE_SAFE_ALLOCA; - if (STRING_MULTIBYTE (string)) return string; - nbytes = count_size_as_multibyte (SDATA (string), SBYTES (string)); + ptrdiff_t nchars = SCHARS (string); + ptrdiff_t nbytes = count_size_as_multibyte (SDATA (string), nchars); /* If all the chars are ASCII, they won't need any more bytes once converted. */ - if (nbytes == SBYTES (string)) + if (nbytes == nchars) return make_multibyte_string (SSDATA (string), nbytes, nbytes); - buf = SAFE_ALLOCA (nbytes); - memcpy (buf, SDATA (string), SBYTES (string)); - str_to_multibyte (buf, nbytes, SBYTES (string)); - - ret = make_multibyte_string ((char *) buf, SCHARS (string), nbytes); - SAFE_FREE (); - + Lisp_Object ret = make_uninit_multibyte_string (nchars, nbytes); + str_to_multibyte (SDATA (ret), SDATA (string), nchars, nbytes); return ret; } |