aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorPaul Eggert2017-07-05 17:51:31 -0700
committerPaul Eggert2017-07-05 18:59:31 -0700
commitd6662694d05be03fdd070353637dd22a324c8b7a (patch)
tree3823cc192290478c041db63121c88afebfccbc13 /src/lread.c
parent24faf6b0d2fe990e9334dd2e3238f749fec87897 (diff)
downloademacs-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/lread.c')
-rw-r--r--src/lread.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/lread.c b/src/lread.c
index 182f96223a5..7c554ba8536 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2426,25 +2426,13 @@ read_escape (Lisp_Object readcharfun, bool stringp)
2426 while (1) 2426 while (1)
2427 { 2427 {
2428 c = READCHAR; 2428 c = READCHAR;
2429 if (c >= '0' && c <= '9') 2429 int digit = char_hexdigit (c);
2430 { 2430 if (digit < 0)
2431 i *= 16;
2432 i += c - '0';
2433 }
2434 else if ((c >= 'a' && c <= 'f')
2435 || (c >= 'A' && c <= 'F'))
2436 {
2437 i *= 16;
2438 if (c >= 'a' && c <= 'f')
2439 i += c - 'a' + 10;
2440 else
2441 i += c - 'A' + 10;
2442 }
2443 else
2444 { 2431 {
2445 UNREAD (c); 2432 UNREAD (c);
2446 break; 2433 break;
2447 } 2434 }
2435 i = (i << 4) + digit;
2448 /* Allow hex escapes as large as ?\xfffffff, because some 2436 /* Allow hex escapes as large as ?\xfffffff, because some
2449 packages use them to denote characters with modifiers. */ 2437 packages use them to denote characters with modifiers. */
2450 if ((CHAR_META | (CHAR_META - 1)) < i) 2438 if ((CHAR_META | (CHAR_META - 1)) < i)
@@ -2474,11 +2462,10 @@ read_escape (Lisp_Object readcharfun, bool stringp)
2474 c = READCHAR; 2462 c = READCHAR;
2475 /* `isdigit' and `isalpha' may be locale-specific, which we don't 2463 /* `isdigit' and `isalpha' may be locale-specific, which we don't
2476 want. */ 2464 want. */
2477 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); 2465 int digit = char_hexdigit (c);
2478 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; 2466 if (digit < 0)
2479 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
2480 else
2481 error ("Non-hex digit used for Unicode escape"); 2467 error ("Non-hex digit used for Unicode escape");
2468 i = (i << 4) + digit;
2482 } 2469 }
2483 if (i > 0x10FFFF) 2470 if (i > 0x10FFFF)
2484 error ("Non-Unicode character: 0x%x", i); 2471 error ("Non-Unicode character: 0x%x", i);