aboutsummaryrefslogtreecommitdiffstats
path: root/src/casefiddle.c
diff options
context:
space:
mode:
authorPaul Eggert2020-04-17 07:57:25 -0700
committerPaul Eggert2020-04-17 09:17:35 -0700
commit27d101832ada36e431ae6cdecb5c82a180566377 (patch)
tree13e20d71f22cf4736bbfa02be54735b1484610bb /src/casefiddle.c
parent3e46a2315f1a999f5811f57a60a2a55f95d8fbb0 (diff)
downloademacs-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/casefiddle.c')
-rw-r--r--src/casefiddle.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 5018b7bb1cd..9a711a8fba6 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -220,6 +220,13 @@ case_character (struct casing_str_buf *buf, struct casing_context *ctx,
220 return changed; 220 return changed;
221} 221}
222 222
223/* If C is not ASCII, make it unibyte. */
224static int
225make_char_unibyte (int c)
226{
227 return ASCII_CHAR_P (c) ? c : CHAR_TO_BYTE8 (c);
228}
229
223static Lisp_Object 230static Lisp_Object
224do_casify_natnum (struct casing_context *ctx, Lisp_Object obj) 231do_casify_natnum (struct casing_context *ctx, Lisp_Object obj)
225{ 232{
@@ -243,13 +250,13 @@ do_casify_natnum (struct casing_context *ctx, Lisp_Object obj)
243 || !NILP (BVAR (current_buffer, 250 || !NILP (BVAR (current_buffer,
244 enable_multibyte_characters))); 251 enable_multibyte_characters)));
245 if (! multibyte) 252 if (! multibyte)
246 MAKE_CHAR_MULTIBYTE (ch); 253 ch = make_char_multibyte (ch);
247 int cased = case_single_character (ctx, ch); 254 int cased = case_single_character (ctx, ch);
248 if (cased == ch) 255 if (cased == ch)
249 return obj; 256 return obj;
250 257
251 if (! multibyte) 258 if (! multibyte)
252 MAKE_CHAR_UNIBYTE (cased); 259 cased = make_char_unibyte (cased);
253 return make_fixed_natnum (cased | flags); 260 return make_fixed_natnum (cased | flags);
254} 261}
255 262
@@ -278,7 +285,7 @@ do_casify_multibyte_string (struct casing_context *ctx, Lisp_Object obj)
278 { 285 {
279 if (dst_end - o < sizeof (struct casing_str_buf)) 286 if (dst_end - o < sizeof (struct casing_str_buf))
280 string_overflow (); 287 string_overflow ();
281 int ch = STRING_CHAR_ADVANCE (src); 288 int ch = string_char_advance (&src);
282 case_character ((struct casing_str_buf *) o, ctx, ch, 289 case_character ((struct casing_str_buf *) o, ctx, ch,
283 size > 1 ? src : NULL); 290 size > 1 ? src : NULL);
284 n += ((struct casing_str_buf *) o)->len_chars; 291 n += ((struct casing_str_buf *) o)->len_chars;
@@ -299,15 +306,14 @@ do_casify_unibyte_string (struct casing_context *ctx, Lisp_Object obj)
299 obj = Fcopy_sequence (obj); 306 obj = Fcopy_sequence (obj);
300 for (i = 0; i < size; i++) 307 for (i = 0; i < size; i++)
301 { 308 {
302 ch = SREF (obj, i); 309 ch = make_char_multibyte (SREF (obj, i));
303 MAKE_CHAR_MULTIBYTE (ch);
304 cased = case_single_character (ctx, ch); 310 cased = case_single_character (ctx, ch);
305 if (ch == cased) 311 if (ch == cased)
306 continue; 312 continue;
307 MAKE_CHAR_UNIBYTE (cased); 313 cased = make_char_unibyte (cased);
308 /* If the char can't be converted to a valid byte, just don't 314 /* If the char can't be converted to a valid byte, just don't
309 change it. */ 315 change it. */
310 if (cased >= 0 && cased < 256) 316 if (SINGLE_BYTE_CHAR_P (cased))
311 SSET (obj, i, cased); 317 SSET (obj, i, cased);
312 } 318 }
313 return obj; 319 return obj;
@@ -397,9 +403,7 @@ do_casify_unibyte_region (struct casing_context *ctx,
397 403
398 for (ptrdiff_t pos = *startp; pos < end; ++pos) 404 for (ptrdiff_t pos = *startp; pos < end; ++pos)
399 { 405 {
400 int ch = FETCH_BYTE (pos); 406 int ch = make_char_multibyte (FETCH_BYTE (pos));
401 MAKE_CHAR_MULTIBYTE (ch);
402
403 int cased = case_single_character (ctx, ch); 407 int cased = case_single_character (ctx, ch);
404 if (cased == ch) 408 if (cased == ch)
405 continue; 409 continue;
@@ -408,8 +412,7 @@ do_casify_unibyte_region (struct casing_context *ctx,
408 if (first < 0) 412 if (first < 0)
409 first = pos; 413 first = pos;
410 414
411 MAKE_CHAR_UNIBYTE (cased); 415 FETCH_BYTE (pos) = make_char_unibyte (cased);
412 FETCH_BYTE (pos) = cased;
413 } 416 }
414 417
415 *startp = first; 418 *startp = first;
@@ -433,8 +436,7 @@ do_casify_multibyte_region (struct casing_context *ctx,
433 436
434 for (; size; --size) 437 for (; size; --size)
435 { 438 {
436 int len; 439 int len, ch = string_char_and_length (BYTE_POS_ADDR (pos_byte), &len);
437 int ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (pos_byte), len);
438 struct casing_str_buf buf; 440 struct casing_str_buf buf;
439 if (!case_character (&buf, ctx, ch, 441 if (!case_character (&buf, ctx, ch,
440 size > 1 ? BYTE_POS_ADDR (pos_byte + len) : NULL)) 442 size > 1 ? BYTE_POS_ADDR (pos_byte + len) : NULL))