diff options
| author | Paul Eggert | 2017-07-05 17:51:31 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-07-05 18:59:31 -0700 |
| commit | d6662694d05be03fdd070353637dd22a324c8b7a (patch) | |
| tree | 3823cc192290478c041db63121c88afebfccbc13 /src/character.c | |
| parent | 24faf6b0d2fe990e9334dd2e3238f749fec87897 (diff) | |
| download | emacs-d6662694d05be03fdd070353637dd22a324c8b7a.tar.gz emacs-d6662694d05be03fdd070353637dd22a324c8b7a.zip | |
Convert hex digits more systematically
This makes the code a bit smaller and presumably faster, as
it substitutes a single lookup for conditional jumps.
* src/character.c (hexdigit): New constant.
(syms_of_character) [HEXDIGIT_IS_CONST]: Initialize it.
* src/character.h (HEXDIGIT_CONST, HEXDIGIT_IS_CONST): New macros.
(hexdigit): New decl.
(char_hexdigit): New inline function.
* src/charset.c: Do not include c-ctype.h.
* src/charset.c (read_hex):
* src/editfns.c (styled_format):
* src/image.c (xbm_scan):
* src/lread.c (read_escape):
* src/regex.c (ISXDIGIT) [emacs]:
Use char_hexdigit insted of doing it by hand.
Diffstat (limited to 'src/character.c')
| -rw-r--r-- | src/character.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/character.c b/src/character.c index cf460540725..1c6020ee468 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -1050,9 +1050,26 @@ blankp (int c) | |||
| 1050 | return XINT (category) == UNICODE_CATEGORY_Zs; /* separator, space */ | 1050 | return XINT (category) == UNICODE_CATEGORY_Zs; /* separator, space */ |
| 1051 | } | 1051 | } |
| 1052 | 1052 | ||
| 1053 | signed char HEXDIGIT_CONST hexdigit[UCHAR_MAX + 1] = | ||
| 1054 | { | ||
| 1055 | #if HEXDIGIT_IS_CONST | ||
| 1056 | [0 ... UCHAR_MAX] = -1, | ||
| 1057 | #endif | ||
| 1058 | ['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4, | ||
| 1059 | ['5'] = 5, ['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9, | ||
| 1060 | ['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15, | ||
| 1061 | ['a'] = 10, ['b'] = 11, ['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15 | ||
| 1062 | }; | ||
| 1063 | |||
| 1053 | void | 1064 | void |
| 1054 | syms_of_character (void) | 1065 | syms_of_character (void) |
| 1055 | { | 1066 | { |
| 1067 | #if !HEXDIGIT_IS_CONST | ||
| 1068 | /* Set the non-hex digit values to -1. */ | ||
| 1069 | for (int i = 0; i <= UCHAR_MAX; i++) | ||
| 1070 | hexdigit[i] -= i != '0' && !hexdigit[i]; | ||
| 1071 | #endif | ||
| 1072 | |||
| 1056 | DEFSYM (Qcharacterp, "characterp"); | 1073 | DEFSYM (Qcharacterp, "characterp"); |
| 1057 | DEFSYM (Qauto_fill_chars, "auto-fill-chars"); | 1074 | DEFSYM (Qauto_fill_chars, "auto-fill-chars"); |
| 1058 | 1075 | ||