diff options
| author | Paul Eggert | 2020-04-17 07:57:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-04-17 09:17:35 -0700 |
| commit | 3e46a2315f1a999f5811f57a60a2a55f95d8fbb0 (patch) | |
| tree | 64e35b78bb77f3eba5148650fb7a98bbda7f14d6 /src/buffer.h | |
| parent | 7f1dae114dffbf4bdec60e38ada4eb0673cfb4e2 (diff) | |
| download | emacs-3e46a2315f1a999f5811f57a60a2a55f95d8fbb0.tar.gz emacs-3e46a2315f1a999f5811f57a60a2a55f95d8fbb0.zip | |
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) | |||
| 1523 | return !uppercasep (c) && upcase (c) != c; | 1523 | return !uppercasep (c) && upcase (c) != c; |
| 1524 | } | 1524 | } |
| 1525 | 1525 | ||
| 1526 | /* Return a non-outlandish value for the tab width. */ | ||
| 1527 | |||
| 1528 | INLINE int | ||
| 1529 | sanitize_tab_width (Lisp_Object width) | ||
| 1530 | { | ||
| 1531 | return (FIXNUMP (width) && 0 < XFIXNUM (width) && XFIXNUM (width) <= 1000 | ||
| 1532 | ? XFIXNUM (width) : 8); | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | INLINE int | ||
| 1536 | SANE_TAB_WIDTH (struct buffer *buf) | ||
| 1537 | { | ||
| 1538 | return sanitize_tab_width (BVAR (buf, tab_width)); | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | /* Return a non-outlandish value for a character width. */ | ||
| 1542 | |||
| 1543 | INLINE int | ||
| 1544 | sanitize_char_width (EMACS_INT width) | ||
| 1545 | { | ||
| 1546 | return 0 <= width && width <= 1000 ? width : 1000; | ||
| 1547 | } | ||
| 1548 | |||
| 1549 | /* Return the width of character C. The width is measured by how many | ||
| 1550 | columns C will occupy on the screen when displayed in the current | ||
| 1551 | buffer. The name CHARACTER_WIDTH avoids a collision with <limits.h> | ||
| 1552 | CHAR_WIDTH. */ | ||
| 1553 | |||
| 1554 | INLINE int | ||
| 1555 | CHARACTER_WIDTH (int c) | ||
| 1556 | { | ||
| 1557 | return (0x20 <= c && c < 0x7f ? 1 | ||
| 1558 | : 0x7f < c ? (sanitize_char_width | ||
| 1559 | (XFIXNUM (CHAR_TABLE_REF (Vchar_width_table, c)))) | ||
| 1560 | : c == '\t' ? SANE_TAB_WIDTH (current_buffer) | ||
| 1561 | : c == '\n' ? 0 | ||
| 1562 | : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4); | ||
| 1563 | } | ||
| 1564 | |||
| 1526 | INLINE_HEADER_END | 1565 | INLINE_HEADER_END |
| 1527 | 1566 | ||
| 1528 | #endif /* EMACS_BUFFER_H */ | 1567 | #endif /* EMACS_BUFFER_H */ |