From c03b816016f8cc2f15d275e7ad23448366489277 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 3 Feb 2018 20:29:00 -0800 Subject: [PATCH 1/4] Simplify print_object a bit * src/print.c (print_object): Simplify by using C99 constructs, and by taking advantage of the fact that Lisp strings are are followed by null bytes. --- src/print.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/print.c b/src/print.c index b3c0f6f..d3eb49d 100644 --- a/src/print.c +++ b/src/print.c @@ -1916,38 +1916,29 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) case Lisp_Symbol: { bool confusing; - unsigned char *p = SDATA (SYMBOL_NAME (obj)); - unsigned char *end = p + SBYTES (SYMBOL_NAME (obj)); - int c; - ptrdiff_t i, i_byte; - ptrdiff_t size_byte; - Lisp_Object name; - - name = SYMBOL_NAME (obj); - - if (p != end && (*p == '-' || *p == '+')) p++; - if (p == end) - confusing = 0; + Lisp_Object name = SYMBOL_NAME (obj); + ptrdiff_t size_byte = SBYTES (name); + unsigned char *p = SDATA (name); + unsigned char *end = p + size_byte; + /* If symbol name begins with a digit, and ends with a digit, and contains nothing but digits and `e', it could be treated as a number. So set CONFUSING. - Symbols that contain periods could also be taken as numbers, - but periods are always escaped, so we don't have to worry - about them here. */ - else if (*p >= '0' && *p <= '9' - && end[-1] >= '0' && end[-1] <= '9') + Symbols that contain '.' or '#' could also be taken as + numbers, but these are always escaped so don't worry about + them here. */ + if (c_isdigit (p[*p == '-' || *p == '+']) && c_isdigit (end[-1])) { - while (p != end && ((*p >= '0' && *p <= '9') - /* Needed for \2e10. */ - || *p == 'e' || *p == 'E')) + /* Check for 'e' too; needed for \2e10. */ + do p++; + while (c_isdigit (*p) || *p == 'e' || *p == 'E'); + confusing = (end == p); } else - confusing = 0; - - size_byte = SBYTES (name); + confusing = false; if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (obj)) @@ -1958,10 +1949,11 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) break; } - for (i = 0, i_byte = 0; i_byte < size_byte;) + for (ptrdiff_t i = 0, i_byte = 0; i_byte < size_byte;) { /* Here, we must convert each multi-byte form to the corresponding character code before handing it to PRINTCHAR. */ + int c; FETCH_STRING_CHAR_ADVANCE (c, name, i, i_byte); maybe_quit (); -- 2.7.4