summaryrefslogtreecommitdiff
path: root/src/fns.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2022-07-11 13:43:34 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2022-07-11 13:52:01 +0200
commit5990da629074b09212d7dea31811d0429e3e2fb8 (patch)
tree4e2081294c1efc440d98ee06187b8a00c3e89c49 /src/fns.c
parent050252043fe85e12412de311a08f0159cd89e92a (diff)
downloademacs-5990da629074b09212d7dea31811d0429e3e2fb8.tar.gz
Simplify str_to_multibyte and related code
* src/character.h (str_to_multibyte): * src/character.c (str_to_multibyte): Remove `nbytes` argument; return it instead. Copy forwards. * src/fns.c (concat_to_string, Fstring_make_multibyte): Use str_to_multibyte. (string_make_multibyte): Remove. (string_to_multibyte): * src/print.c (print_string): Adapt calls.
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c50
1 files changed, 14 insertions, 36 deletions
diff --git a/src/fns.c b/src/fns.c
index 7d8f957ef98..eb83471649e 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -856,9 +856,8 @@ concat_to_string (ptrdiff_t nargs, Lisp_Object *args)
else
{
/* Copy a single-byte string to a multibyte string. */
- toindex_byte += copy_text (SDATA (arg),
- SDATA (result) + toindex_byte,
- nchars, 0, 1);
+ toindex_byte += str_to_multibyte (SDATA (result) + toindex_byte,
+ SDATA (arg), nchars);
}
toindex += nchars;
}
@@ -1205,37 +1204,6 @@ string_byte_to_char (Lisp_Object string, ptrdiff_t byte_index)
return i;
}
-/* Convert STRING to a multibyte string. */
-
-static Lisp_Object
-string_make_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),
- SCHARS (string));
- /* If all the chars are ASCII, they won't need any more bytes
- once converted. In that case, we can return STRING itself. */
- if (nbytes == SBYTES (string))
- return string;
-
- buf = SAFE_ALLOCA (nbytes);
- copy_text (SDATA (string), buf, SBYTES (string),
- 0, 1);
-
- ret = make_multibyte_string ((char *) buf, SCHARS (string), nbytes);
- SAFE_FREE ();
-
- return ret;
-}
-
-
/* Convert STRING (if unibyte) to a multibyte string without changing
the number of characters. Characters 0x80..0xff are interpreted as
raw bytes. */
@@ -1254,7 +1222,7 @@ string_to_multibyte (Lisp_Object string)
return make_multibyte_string (SSDATA (string), nbytes, nbytes);
Lisp_Object ret = make_uninit_multibyte_string (nchars, nbytes);
- str_to_multibyte (SDATA (ret), SDATA (string), nchars, nbytes);
+ str_to_multibyte (SDATA (ret), SDATA (string), nchars);
return ret;
}
@@ -1299,7 +1267,17 @@ string the same way whether it is unibyte or multibyte.) */)
{
CHECK_STRING (string);
- return string_make_multibyte (string);
+ if (STRING_MULTIBYTE (string))
+ return string;
+
+ ptrdiff_t nchars = SCHARS (string);
+ ptrdiff_t nbytes = count_size_as_multibyte (SDATA (string), nchars);
+ if (nbytes == nchars)
+ return string;
+
+ Lisp_Object ret = make_uninit_multibyte_string (nchars, nbytes);
+ str_to_multibyte (SDATA (ret), SDATA (string), nchars);
+ return ret;
}
DEFUN ("string-make-unibyte", Fstring_make_unibyte, Sstring_make_unibyte,