diff options
| author | Paul Eggert | 2020-04-17 07:57:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-04-17 09:17:35 -0700 |
| commit | 27d101832ada36e431ae6cdecb5c82a180566377 (patch) | |
| tree | 13e20d71f22cf4736bbfa02be54735b1484610bb /src/coding.c | |
| parent | 3e46a2315f1a999f5811f57a60a2a55f95d8fbb0 (diff) | |
| download | emacs-27d101832ada36e431ae6cdecb5c82a180566377.tar.gz emacs-27d101832ada36e431ae6cdecb5c82a180566377.zip | |
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.c | 61 |
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) | |||
| 643 | else \ | 643 | else \ |
| 644 | { \ | 644 | { \ |
| 645 | src--; \ | 645 | src--; \ |
| 646 | c = - string_char (src, &src, NULL); \ | 646 | c = - string_char_advance (&src); \ |
| 647 | record_conversion_result \ | 647 | record_conversion_result \ |
| 648 | (coding, CODING_RESULT_INVALID_SRC); \ | 648 | (coding, CODING_RESULT_INVALID_SRC); \ |
| 649 | } \ | 649 | } \ |
| @@ -728,7 +728,7 @@ growable_destination (struct coding_system *coding) | |||
| 728 | unsigned ch = (c); \ | 728 | unsigned ch = (c); \ |
| 729 | if (ch >= 0x80) \ | 729 | if (ch >= 0x80) \ |
| 730 | ch = BYTE8_TO_CHAR (ch); \ | 730 | ch = BYTE8_TO_CHAR (ch); \ |
| 731 | CHAR_STRING_ADVANCE (ch, dst); \ | 731 | dst += CHAR_STRING (ch, dst); \ |
| 732 | } \ | 732 | } \ |
| 733 | else \ | 733 | else \ |
| 734 | *dst++ = (c); \ | 734 | *dst++ = (c); \ |
| @@ -747,11 +747,11 @@ growable_destination (struct coding_system *coding) | |||
| 747 | ch = (c1); \ | 747 | ch = (c1); \ |
| 748 | if (ch >= 0x80) \ | 748 | if (ch >= 0x80) \ |
| 749 | ch = BYTE8_TO_CHAR (ch); \ | 749 | ch = BYTE8_TO_CHAR (ch); \ |
| 750 | CHAR_STRING_ADVANCE (ch, dst); \ | 750 | dst += CHAR_STRING (ch, dst); \ |
| 751 | ch = (c2); \ | 751 | ch = (c2); \ |
| 752 | if (ch >= 0x80) \ | 752 | if (ch >= 0x80) \ |
| 753 | ch = BYTE8_TO_CHAR (ch); \ | 753 | ch = BYTE8_TO_CHAR (ch); \ |
| 754 | CHAR_STRING_ADVANCE (ch, dst); \ | 754 | dst += CHAR_STRING (ch, dst); \ |
| 755 | } \ | 755 | } \ |
| 756 | else \ | 756 | else \ |
| 757 | { \ | 757 | { \ |
| @@ -884,18 +884,18 @@ record_conversion_result (struct coding_system *coding, | |||
| 884 | 884 | ||
| 885 | 885 | ||
| 886 | /* Store multibyte form of the character C in P, and advance P to the | 886 | /* Store multibyte form of the character C in P, and advance P to the |
| 887 | end of the multibyte form. This used to be like CHAR_STRING_ADVANCE | 887 | end of the multibyte form. This used to be like adding CHAR_STRING |
| 888 | without ever calling MAYBE_UNIFY_CHAR, but nowadays we don't call | 888 | without ever calling MAYBE_UNIFY_CHAR, but nowadays we don't call |
| 889 | MAYBE_UNIFY_CHAR in CHAR_STRING_ADVANCE. */ | 889 | MAYBE_UNIFY_CHAR in CHAR_STRING. */ |
| 890 | 890 | ||
| 891 | #define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) CHAR_STRING_ADVANCE(c, p) | 891 | #define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) ((p) += CHAR_STRING (c, p)) |
| 892 | 892 | ||
| 893 | /* Return the character code of character whose multibyte form is at | 893 | /* Return the character code of character whose multibyte form is at |
| 894 | P, and advance P to the end of the multibyte form. This used to be | 894 | P, and advance P to the end of the multibyte form. This used to be |
| 895 | like STRING_CHAR_ADVANCE without ever calling MAYBE_UNIFY_CHAR, but | 895 | like string_char_advance without ever calling MAYBE_UNIFY_CHAR, but |
| 896 | nowadays STRING_CHAR_ADVANCE doesn't call MAYBE_UNIFY_CHAR. */ | 896 | nowadays string_char_advance doesn't call MAYBE_UNIFY_CHAR. */ |
| 897 | 897 | ||
| 898 | #define STRING_CHAR_ADVANCE_NO_UNIFY(p) STRING_CHAR_ADVANCE(p) | 898 | #define STRING_CHAR_ADVANCE_NO_UNIFY(p) string_char_advance (&(p)) |
| 899 | 899 | ||
| 900 | /* Set coding->source from coding->src_object. */ | 900 | /* Set coding->source from coding->src_object. */ |
| 901 | 901 | ||
| @@ -5131,7 +5131,7 @@ decode_coding_ccl (struct coding_system *coding) | |||
| 5131 | while (i < 1024 && p < src_end) | 5131 | while (i < 1024 && p < src_end) |
| 5132 | { | 5132 | { |
| 5133 | source_byteidx[i] = p - src; | 5133 | source_byteidx[i] = p - src; |
| 5134 | source_charbuf[i++] = STRING_CHAR_ADVANCE (p); | 5134 | source_charbuf[i++] = string_char_advance (&p); |
| 5135 | } | 5135 | } |
| 5136 | source_byteidx[i] = p - src; | 5136 | source_byteidx[i] = p - src; |
| 5137 | } | 5137 | } |
| @@ -5308,15 +5308,10 @@ encode_coding_raw_text (struct coding_system *coding) | |||
| 5308 | } | 5308 | } |
| 5309 | else | 5309 | else |
| 5310 | { | 5310 | { |
| 5311 | unsigned char str[MAX_MULTIBYTE_LENGTH], *p0 = str, *p1 = str; | 5311 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
| 5312 | 5312 | int len = CHAR_STRING (c, str); | |
| 5313 | CHAR_STRING_ADVANCE (c, p1); | 5313 | for (int i = 0; i < len; i++) |
| 5314 | do | 5314 | EMIT_ONE_BYTE (str[i]); |
| 5315 | { | ||
| 5316 | EMIT_ONE_BYTE (*p0); | ||
| 5317 | p0++; | ||
| 5318 | } | ||
| 5319 | while (p0 < p1); | ||
| 5320 | } | 5315 | } |
| 5321 | } | 5316 | } |
| 5322 | else | 5317 | else |
| @@ -5342,7 +5337,7 @@ encode_coding_raw_text (struct coding_system *coding) | |||
| 5342 | else if (CHAR_BYTE8_P (c)) | 5337 | else if (CHAR_BYTE8_P (c)) |
| 5343 | *dst++ = CHAR_TO_BYTE8 (c); | 5338 | *dst++ = CHAR_TO_BYTE8 (c); |
| 5344 | else | 5339 | else |
| 5345 | CHAR_STRING_ADVANCE (c, dst); | 5340 | dst += CHAR_STRING (c, dst); |
| 5346 | } | 5341 | } |
| 5347 | } | 5342 | } |
| 5348 | else | 5343 | else |
| @@ -7457,7 +7452,7 @@ decode_coding (struct coding_system *coding) | |||
| 7457 | if (coding->src_multibyte | 7452 | if (coding->src_multibyte |
| 7458 | && CHAR_BYTE8_HEAD_P (*src) && nbytes > 0) | 7453 | && CHAR_BYTE8_HEAD_P (*src) && nbytes > 0) |
| 7459 | { | 7454 | { |
| 7460 | c = STRING_CHAR_ADVANCE (src); | 7455 | c = string_char_advance (&src); |
| 7461 | nbytes--; | 7456 | nbytes--; |
| 7462 | } | 7457 | } |
| 7463 | else | 7458 | else |
| @@ -7551,10 +7546,8 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit, | |||
| 7551 | len = SCHARS (components); | 7546 | len = SCHARS (components); |
| 7552 | i = i_byte = 0; | 7547 | i = i_byte = 0; |
| 7553 | while (i < len) | 7548 | while (i < len) |
| 7554 | { | 7549 | *buf++ = fetch_string_char_advance (components, |
| 7555 | FETCH_STRING_CHAR_ADVANCE (*buf, components, i, i_byte); | 7550 | &i, &i_byte); |
| 7556 | buf++; | ||
| 7557 | } | ||
| 7558 | } | 7551 | } |
| 7559 | else if (FIXNUMP (components)) | 7552 | else if (FIXNUMP (components)) |
| 7560 | { | 7553 | { |
| @@ -7715,7 +7708,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table, | |||
| 7715 | 7708 | ||
| 7716 | lookup_buf[0] = c; | 7709 | lookup_buf[0] = c; |
| 7717 | for (i = 1; i < max_lookup && p < src_end; i++) | 7710 | for (i = 1; i < max_lookup && p < src_end; i++) |
| 7718 | lookup_buf[i] = STRING_CHAR_ADVANCE (p); | 7711 | lookup_buf[i] = string_char_advance (&p); |
| 7719 | lookup_buf_end = lookup_buf + i; | 7712 | lookup_buf_end = lookup_buf + i; |
| 7720 | trans = get_translation (trans, lookup_buf, lookup_buf_end, | 7713 | trans = get_translation (trans, lookup_buf, lookup_buf_end, |
| 7721 | &from_nchars); | 7714 | &from_nchars); |
| @@ -9075,7 +9068,7 @@ DEFUN ("find-coding-systems-region-internal", | |||
| 9075 | p++; | 9068 | p++; |
| 9076 | else | 9069 | else |
| 9077 | { | 9070 | { |
| 9078 | c = STRING_CHAR_ADVANCE (p); | 9071 | c = string_char_advance (&p); |
| 9079 | if (!NILP (char_table_ref (work_table, c))) | 9072 | if (!NILP (char_table_ref (work_table, c))) |
| 9080 | /* This character was already checked. Ignore it. */ | 9073 | /* This character was already checked. Ignore it. */ |
| 9081 | continue; | 9074 | continue; |
| @@ -9208,7 +9201,7 @@ to the string and treated as in `substring'. */) | |||
| 9208 | p = GAP_END_ADDR; | 9201 | p = GAP_END_ADDR; |
| 9209 | } | 9202 | } |
| 9210 | 9203 | ||
| 9211 | c = STRING_CHAR_ADVANCE (p); | 9204 | c = string_char_advance (&p); |
| 9212 | if (! (ASCII_CHAR_P (c) && ascii_compatible) | 9205 | if (! (ASCII_CHAR_P (c) && ascii_compatible) |
| 9213 | && ! char_charset (translate_char (translation_table, c), | 9206 | && ! char_charset (translate_char (translation_table, c), |
| 9214 | charset_list, NULL)) | 9207 | charset_list, NULL)) |
| @@ -9326,7 +9319,7 @@ is nil. */) | |||
| 9326 | p++; | 9319 | p++; |
| 9327 | else | 9320 | else |
| 9328 | { | 9321 | { |
| 9329 | c = STRING_CHAR_ADVANCE (p); | 9322 | c = string_char_advance (&p); |
| 9330 | 9323 | ||
| 9331 | charset_map_loaded = 0; | 9324 | charset_map_loaded = 0; |
| 9332 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | 9325 | for (tail = list; CONSP (tail); tail = XCDR (tail)) |
| @@ -9728,7 +9721,7 @@ encode_string_utf_8 (Lisp_Object string, Lisp_Object buffer, | |||
| 9728 | || (len == 2 ? ! CHAR_BYTE8_HEAD_P (c) | 9721 | || (len == 2 ? ! CHAR_BYTE8_HEAD_P (c) |
| 9729 | : (EQ (handle_over_uni, Qt) | 9722 | : (EQ (handle_over_uni, Qt) |
| 9730 | || (len == 4 | 9723 | || (len == 4 |
| 9731 | && string_char (p, NULL, NULL) <= MAX_UNICODE_CHAR)))) | 9724 | && STRING_CHAR (p) <= MAX_UNICODE_CHAR)))) |
| 9732 | { | 9725 | { |
| 9733 | p += len; | 9726 | p += len; |
| 9734 | continue; | 9727 | continue; |
| @@ -10010,8 +10003,7 @@ decode_string_utf_8 (Lisp_Object string, const char *str, ptrdiff_t str_len, | |||
| 10010 | && (len == 3 | 10003 | && (len == 3 |
| 10011 | || (UTF_8_EXTRA_OCTET_P (p[3]) | 10004 | || (UTF_8_EXTRA_OCTET_P (p[3]) |
| 10012 | && len == 4 | 10005 | && len == 4 |
| 10013 | && (string_char (p, NULL, NULL) | 10006 | && STRING_CHAR (p) <= MAX_UNICODE_CHAR))))) |
| 10014 | <= MAX_UNICODE_CHAR)))))) | ||
| 10015 | { | 10007 | { |
| 10016 | p += len; | 10008 | p += len; |
| 10017 | continue; | 10009 | continue; |
| @@ -10148,8 +10140,7 @@ decode_string_utf_8 (Lisp_Object string, const char *str, ptrdiff_t str_len, | |||
| 10148 | mlen++); | 10140 | mlen++); |
| 10149 | if (mlen == len | 10141 | if (mlen == len |
| 10150 | && (len <= 3 | 10142 | && (len <= 3 |
| 10151 | || (len == 4 | 10143 | || (len == 4 && STRING_CHAR (p) <= MAX_UNICODE_CHAR) |
| 10152 | && string_char (p, NULL, NULL) <= MAX_UNICODE_CHAR) | ||
| 10153 | || EQ (handle_over_uni, Qt))) | 10144 | || EQ (handle_over_uni, Qt))) |
| 10154 | { | 10145 | { |
| 10155 | p += len; | 10146 | p += len; |