summaryrefslogtreecommitdiff
path: root/src/coding.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-04-17 07:57:25 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-04-17 09:17:35 -0700
commit27d101832ada36e431ae6cdecb5c82a180566377 (patch)
tree13e20d71f22cf4736bbfa02be54735b1484610bb /src/coding.c
parent3e46a2315f1a999f5811f57a60a2a55f95d8fbb0 (diff)
downloademacs-27d101832ada36e431ae6cdecb5c82a180566377.tar.gz
Prefer more inline functions in character.h
* src/buffer.h (fetch_char_advance, fetch_char_advance_no_check) (buf_next_char_len, next_char_len, buf_prev_char_len) (prev_char_len, inc_both, dec_both): New inline functions, replacing the old character.h macros FETCH_CHAR_ADVANCE, FETCH_CHAR_ADVANCE_NO_CHECK, BUF_INC_POS, INC_POS, BUF_DEC_POS, DEC_POS, INC_BOTH, DEC_BOTH respectively. All callers changed. These new functions all assume buffer primitives and so need to be here rather than in character.h. * src/casefiddle.c (make_char_unibyte): New static function, replacing the old MAKE_CHAR_UNIBYTE macro. All callers changed. (do_casify_unibyte_string): Use SINGLE_BYTE_CHAR_P instead of open-coding it. * src/ccl.c (GET_TRANSLATION_TABLE): New static function, replacing the old macro of the same name. * src/character.c (string_char): Omit 2nd arg. 3rd arg can no longer be NULL. All callers changed. * src/character.h (SINGLE_BYTE_CHAR_P): Move up. (MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE, PREV_CHAR_BOUNDARY) (STRING_CHAR_AND_LENGTH, STRING_CHAR_ADVANCE) (FETCH_STRING_CHAR_ADVANCE) (FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE) (FETCH_STRING_CHAR_ADVANCE_NO_CHECK, FETCH_CHAR_ADVANCE) (FETCH_CHAR_ADVANCE_NO_CHECK, INC_POS, DEC_POS, INC_BOTH) (DEC_BOTH, BUF_INC_POS, BUF_DEC_POS): Remove. (make_char_multibyte): New static function, replacing the old macro MAKE_CHAR_MULTIBYTE. All callers changed. (CHAR_STRING_ADVANCE): Remove; all callers changed to use CHAR_STRING. (NEXT_CHAR_BOUNDARY): Remove; it was unused. (raw_prev_char_len): New inline function, replacing the old PREV_CHAR_BOUNDARY macro. All callers changed. (string_char_and_length): New inline function, replacing the old STRING_CHAR_AND_LENGTH macro. All callers changed. (STRING_CHAR): Rewrite in terms of string_char_and_length. (string_char_advance): New inline function, replacing the old STRING_CHAR_ADVANCE macro. All callers changed. (fetch_string_char_advance): New inline function, replacing the old FETCH_STRING_CHAR_ADVANCE macro. All callers changed. (fetch_string_char_as_multibyte_advance): New inline function, replacing the old FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE macro. All callers changed. (fetch_string_char_advance_no_check): New inline function, replacing the old FETCH_STRING_CHAR_ADVANCE_NO_CHECK macro. All callers changed. * src/regex-emacs.c (HEAD_ADDR_VSTRING): Remove; no longer used. * src/syntax.c (scan_lists): Use dec_bytepos instead of open-coding it. * src/xdisp.c (string_char_and_length): Rename from string_char_and_length to avoid name conflict with new function in character.h. All callers changed.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c61
1 files changed, 26 insertions, 35 deletions
diff --git a/src/coding.c b/src/coding.c
index 0daa390bc85..716b0d99792 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -643,7 +643,7 @@ growable_destination (struct coding_system *coding)
else \
{ \
src--; \
- c = - string_char (src, &src, NULL); \
+ c = - string_char_advance (&src); \
record_conversion_result \
(coding, CODING_RESULT_INVALID_SRC); \
} \
@@ -728,7 +728,7 @@ growable_destination (struct coding_system *coding)
unsigned ch = (c); \
if (ch >= 0x80) \
ch = BYTE8_TO_CHAR (ch); \
- CHAR_STRING_ADVANCE (ch, dst); \
+ dst += CHAR_STRING (ch, dst); \
} \
else \
*dst++ = (c); \
@@ -747,11 +747,11 @@ growable_destination (struct coding_system *coding)
ch = (c1); \
if (ch >= 0x80) \
ch = BYTE8_TO_CHAR (ch); \
- CHAR_STRING_ADVANCE (ch, dst); \
+ dst += CHAR_STRING (ch, dst); \
ch = (c2); \
if (ch >= 0x80) \
ch = BYTE8_TO_CHAR (ch); \
- CHAR_STRING_ADVANCE (ch, dst); \
+ dst += CHAR_STRING (ch, dst); \
} \
else \
{ \
@@ -884,18 +884,18 @@ record_conversion_result (struct coding_system *coding,
/* Store multibyte form of the character C in P, and advance P to the
- end of the multibyte form. This used to be like CHAR_STRING_ADVANCE
+ end of the multibyte form. This used to be like adding CHAR_STRING
without ever calling MAYBE_UNIFY_CHAR, but nowadays we don't call
- MAYBE_UNIFY_CHAR in CHAR_STRING_ADVANCE. */
+ MAYBE_UNIFY_CHAR in CHAR_STRING. */
-#define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) CHAR_STRING_ADVANCE(c, p)
+#define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) ((p) += CHAR_STRING (c, p))
/* Return the character code of character whose multibyte form is at
P, and advance P to the end of the multibyte form. This used to be
- like STRING_CHAR_ADVANCE without ever calling MAYBE_UNIFY_CHAR, but
- nowadays STRING_CHAR_ADVANCE doesn't call MAYBE_UNIFY_CHAR. */
+ like string_char_advance without ever calling MAYBE_UNIFY_CHAR, but
+ nowadays string_char_advance doesn't call MAYBE_UNIFY_CHAR. */
-#define STRING_CHAR_ADVANCE_NO_UNIFY(p) STRING_CHAR_ADVANCE(p)
+#define STRING_CHAR_ADVANCE_NO_UNIFY(p) string_char_advance (&(p))
/* Set coding->source from coding->src_object. */
@@ -5131,7 +5131,7 @@ decode_coding_ccl (struct coding_system *coding)
while (i < 1024 && p < src_end)
{
source_byteidx[i] = p - src;
- source_charbuf[i++] = STRING_CHAR_ADVANCE (p);
+ source_charbuf[i++] = string_char_advance (&p);
}
source_byteidx[i] = p - src;
}
@@ -5308,15 +5308,10 @@ encode_coding_raw_text (struct coding_system *coding)
}
else
{
- unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str;
-
- CHAR_STRING_ADVANCE (c, p1);
- do
- {
- EMIT_ONE_BYTE (*p0);
- p0++;
- }
- while (p0 < p1);
+ unsigned char str[MAX_MULTIBYTE_LENGTH];
+ int len = CHAR_STRING (c, str);
+ for (int i = 0; i < len; i++)
+ EMIT_ONE_BYTE (str[i]);
}
}
else
@@ -5342,7 +5337,7 @@ encode_coding_raw_text (struct coding_system *coding)
else if (CHAR_BYTE8_P (c))
*dst++ = CHAR_TO_BYTE8 (c);
else
- CHAR_STRING_ADVANCE (c, dst);
+ dst += CHAR_STRING (c, dst);
}
}
else
@@ -7457,7 +7452,7 @@ decode_coding (struct coding_system *coding)
if (coding->src_multibyte
&& CHAR_BYTE8_HEAD_P (*src) && nbytes > 0)
{
- c = STRING_CHAR_ADVANCE (src);
+ c = string_char_advance (&src);
nbytes--;
}
else
@@ -7551,10 +7546,8 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit,
len = SCHARS (components);
i = i_byte = 0;
while (i < len)
- {
- FETCH_STRING_CHAR_ADVANCE (*buf, components, i, i_byte);
- buf++;
- }
+ *buf++ = fetch_string_char_advance (components,
+ &i, &i_byte);
}
else if (FIXNUMP (components))
{
@@ -7715,7 +7708,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
lookup_buf[0] = c;
for (i = 1; i < max_lookup && p < src_end; i++)
- lookup_buf[i] = STRING_CHAR_ADVANCE (p);
+ lookup_buf[i] = string_char_advance (&p);
lookup_buf_end = lookup_buf + i;
trans = get_translation (trans, lookup_buf, lookup_buf_end,
&from_nchars);
@@ -9075,7 +9068,7 @@ DEFUN ("find-coding-systems-region-internal",
p++;
else
{
- c = STRING_CHAR_ADVANCE (p);
+ c = string_char_advance (&p);
if (!NILP (char_table_ref (work_table, c)))
/* This character was already checked. Ignore it. */
continue;
@@ -9208,7 +9201,7 @@ to the string and treated as in `substring'. */)
p = GAP_END_ADDR;
}
- c = STRING_CHAR_ADVANCE (p);
+ c = string_char_advance (&p);
if (! (ASCII_CHAR_P (c) && ascii_compatible)
&& ! char_charset (translate_char (translation_table, c),
charset_list, NULL))
@@ -9326,7 +9319,7 @@ is nil. */)
p++;
else
{
- c = STRING_CHAR_ADVANCE (p);
+ c = string_char_advance (&p);
charset_map_loaded = 0;
for (tail = list; CONSP (tail); tail = XCDR (tail))
@@ -9728,7 +9721,7 @@ encode_string_utf_8 (Lisp_Object string, Lisp_Object buffer,
|| (len == 2 ? ! CHAR_BYTE8_HEAD_P (c)
: (EQ (handle_over_uni, Qt)
|| (len == 4
- && string_char (p, NULL, NULL) <= MAX_UNICODE_CHAR))))
+ && STRING_CHAR (p) <= MAX_UNICODE_CHAR))))
{
p += len;
continue;
@@ -10010,8 +10003,7 @@ decode_string_utf_8 (Lisp_Object string, const char *str, ptrdiff_t str_len,
&& (len == 3
|| (UTF_8_EXTRA_OCTET_P (p[3])
&& len == 4
- && (string_char (p, NULL, NULL)
- <= MAX_UNICODE_CHAR))))))
+ && STRING_CHAR (p) <= MAX_UNICODE_CHAR)))))
{
p += len;
continue;
@@ -10148,8 +10140,7 @@ decode_string_utf_8 (Lisp_Object string, const char *str, ptrdiff_t str_len,
mlen++);
if (mlen == len
&& (len <= 3
- || (len == 4
- && string_char (p, NULL, NULL) <= MAX_UNICODE_CHAR)
+ || (len == 4 && STRING_CHAR (p) <= MAX_UNICODE_CHAR)
|| EQ (handle_over_uni, Qt)))
{
p += len;