diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-04-17 07:57:25 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-04-17 09:17:35 -0700 |
commit | 3e46a2315f1a999f5811f57a60a2a55f95d8fbb0 (patch) | |
tree | 64e35b78bb77f3eba5148650fb7a98bbda7f14d6 /src/buffer.h | |
parent | 7f1dae114dffbf4bdec60e38ada4eb0673cfb4e2 (diff) | |
download | emacs-3e46a2315f1a999f5811f57a60a2a55f95d8fbb0.tar.gz |
Prefer inline functions in character.h
In character.h, replace macros with inline functions or enums
when this is easy. This improves maintainability and
on my platform (Fedora 31 x86-64, gcc -O2) improved CPU
performance very slightly (0.3%) on ‘make compile-always’.
* src/buffer.h (SANE_TAB_WIDTH, CHARACTER_WIDTH):
Move here from character.h, and make them inline functions.
Tune CHARACTER_WIDTH so that ASCII_CHAR_WIDTH is no longer needed.
(sanitize_tab_width, sanitize_char_width):
Move here from character.h.
* src/character.h (MAX_CHAR, MAX_UNICODE_CHAR, MAX_1_BYTE_CHAR)
(MAX_2_BYTE_CHAR, MAX_3_BYTE_CHAR, MAX_4_BYTE_CHAR)
(MAX_5_BYTE_CHAR, MIN_MULTIBYTE_LEADING_CODE)
(MAX_MULTIBYTE_LEADING_CODE, MAX_MULTIBYTE_LENGTH):
Now enum constants instead of macros.
* src/character.h (CHAR_BYTES): Redo to avoid conditional branches.
(CHAR_BYTE8_P, BYTE8_TO_CHAR, UNIBYTE_TO_CHAR, CHAR_TO_BYTE8)
(CHAR_TO_BYTE_SAFE, CHAR_BYTE8_HEAD_P, CHARACTERP)
(CHECK_CHARACTER, CHECK_CHARACTER_CAR, CHECK_CHARACTER_CDR)
(CHAR_PRINTABLE_P, CHAR_BYTES, CHAR_LEADING_CODE, BYTE8_STRING)
(LEADING_CODE_P, TRAILING_CODE_P, CHAR_HEAD_P)
(BYTES_BY_CHAR_HEAD):
Now inline functions instead of macros.
(ASCII_CHAR_WIDTH): Remove; no longer used.
* src/conf_post.h (ATTRIBUTE_PURE): New macro.
* src/lisp.h (char_table_ref): Use it, for better inlining.
* src/fns.c (base64_decode_1): Add now-necessary casts.
Diffstat (limited to 'src/buffer.h')
-rw-r--r-- | src/buffer.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/buffer.h b/src/buffer.h index abb1294d038..9875b8a447b 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1523,6 +1523,45 @@ lowercasep (int c) return !uppercasep (c) && upcase (c) != c; } +/* Return a non-outlandish value for the tab width. */ + +INLINE int +sanitize_tab_width (Lisp_Object width) +{ + return (FIXNUMP (width) && 0 < XFIXNUM (width) && XFIXNUM (width) <= 1000 + ? XFIXNUM (width) : 8); +} + +INLINE int +SANE_TAB_WIDTH (struct buffer *buf) +{ + return sanitize_tab_width (BVAR (buf, tab_width)); +} + +/* Return a non-outlandish value for a character width. */ + +INLINE int +sanitize_char_width (EMACS_INT width) +{ + return 0 <= width && width <= 1000 ? width : 1000; +} + +/* Return the width of character C. The width is measured by how many + columns C will occupy on the screen when displayed in the current + buffer. The name CHARACTER_WIDTH avoids a collision with <limits.h> + CHAR_WIDTH. */ + +INLINE int +CHARACTER_WIDTH (int c) +{ + return (0x20 <= c && c < 0x7f ? 1 + : 0x7f < c ? (sanitize_char_width + (XFIXNUM (CHAR_TABLE_REF (Vchar_width_table, c)))) + : c == '\t' ? SANE_TAB_WIDTH (current_buffer) + : c == '\n' ? 0 + : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4); +} + INLINE_HEADER_END #endif /* EMACS_BUFFER_H */ |