From 59f3c86659c061e2673eb0da0bc78528d30f8f76 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Mon, 19 Dec 2016 16:01:09 -0500 Subject: [PATCH] Create less garbage to collect while reading symbols. * src/lread.c (read1): When interning a symbol, only create a new string object for the name if we're going to use it for a new symbol object. --- src/lread.c | 62 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/src/lread.c b/src/lread.c index d6a7e55b98a..3004e2b1915 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3442,25 +3442,51 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) if (! NILP (result)) return unbind_to (count, result); } + { + Lisp_Object result; + ptrdiff_t nbytes = p - read_buffer; + ptrdiff_t nchars + = (multibyte + ? multibyte_chars_in_text ((unsigned char *) read_buffer, + nbytes) + : nbytes); + + if (uninterned_symbol) + { + Lisp_Object name + = ((! NILP (Vpurify_flag) + ? make_pure_string : make_specified_string) + (read_buffer, nchars, nbytes, multibyte)); + result = Fmake_symbol (name); + } + else + { + /* Don't create the string object for the name unless + we're going to retain it in a new symbol. - ptrdiff_t nbytes = p - read_buffer; - ptrdiff_t nchars - = (multibyte - ? multibyte_chars_in_text ((unsigned char *) read_buffer, - nbytes) - : nbytes); - Lisp_Object name = ((uninterned_symbol && ! NILP (Vpurify_flag) - ? make_pure_string : make_specified_string) - (read_buffer, nchars, nbytes, multibyte)); - Lisp_Object result = (uninterned_symbol ? Fmake_symbol (name) - : Fintern (name, Qnil)); - - if (EQ (Vread_with_symbol_positions, Qt) - || EQ (Vread_with_symbol_positions, readcharfun)) - Vread_symbol_positions_list - = Fcons (Fcons (result, make_number (start_position)), - Vread_symbol_positions_list); - return unbind_to (count, result); + Like intern_1 but supports multibyte names. */ + Lisp_Object obarray = check_obarray (Vobarray); + Lisp_Object tem = oblookup (obarray, read_buffer, + nchars, nbytes); + + if (SYMBOLP (tem)) + result = tem; + else + { + Lisp_Object name + = make_specified_string (read_buffer, nchars, nbytes, + multibyte); + result = intern_driver (name, obarray, tem); + } + } + + if (EQ (Vread_with_symbol_positions, Qt) + || EQ (Vread_with_symbol_positions, readcharfun)) + Vread_symbol_positions_list + = Fcons (Fcons (result, make_number (start_position)), + Vread_symbol_positions_list); + return unbind_to (count, result); + } } } } -- 2.39.2