>From f9e3085864ac6ebc799dd37b36097cb83bc9fd05 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Jun 2018 19:12:27 -0700 Subject: [PATCH 03/10] Avoid Lisp_Misc allocation if C stack suffices * src/fileio.c (union read_non_regular): New type. (read_non_regular, Finsert_file_contents): Use it to avoid allocating a Lisp_Misc. * src/keymap.c (union map_keymap): New type. (map_keymap_char_table_item, map_keymap_internal): Use it to avoid allocating a Lisp_Misc. --- src/fileio.c | 28 +++++++++++++++++----------- src/keymap.c | 25 ++++++++++++++++++------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index e8d966e163..89c5a14547 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3365,20 +3365,26 @@ decide_coding_unwind (Lisp_Object unwind_data) bset_undo_list (current_buffer, undo_list); } -/* Read from a non-regular file. STATE is a Lisp_Save_Value - object where slot 0 is the file descriptor, slot 1 specifies - an offset to put the read bytes, and slot 2 is the maximum - amount of bytes to read. Value is the number of bytes read. */ +/* Read from a non-regular file. Return the number of bytes read. */ + +union read_non_regular +{ + struct + { + int fd; + ptrdiff_t inserted, trytry; + } s; + GCALIGNED_UNION +}; static Lisp_Object read_non_regular (Lisp_Object state) { - int nbytes = emacs_read_quit (XSAVE_INTEGER (state, 0), + union read_non_regular *data = XINTPTR (state); + int nbytes = emacs_read_quit (data->s.fd, ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE - + XSAVE_INTEGER (state, 1)), - XSAVE_INTEGER (state, 2)); - /* Fast recycle this object for the likely next call. */ - free_misc (state); + + data->s.inserted), + data->s.trytry); return make_number (nbytes); } @@ -4233,9 +4239,9 @@ by calling `format-decode', which see. */) /* Read from the file, capturing `quit'. When an error occurs, end the loop, and arrange for a quit to be signaled after decoding the text we read. */ + union read_non_regular data = {{fd, inserted, trytry}}; nbytes = internal_condition_case_1 - (read_non_regular, - make_save_int_int_int (fd, inserted, trytry), + (read_non_regular, make_pointer_integer (&data), Qerror, read_non_regular_quit); if (NILP (nbytes)) diff --git a/src/keymap.c b/src/keymap.c index c8cc933e78..32ee22759d 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -546,19 +546,28 @@ map_keymap_item (map_keymap_function_t fun, Lisp_Object args, Lisp_Object key, L (*fun) (key, val, args, data); } +union map_keymap +{ + struct + { + map_keymap_function_t fun; + Lisp_Object args; + void *data; + } s; + GCALIGNED_UNION +}; + static void map_keymap_char_table_item (Lisp_Object args, Lisp_Object key, Lisp_Object val) { if (!NILP (val)) { - map_keymap_function_t fun - = (map_keymap_function_t) XSAVE_FUNCPOINTER (args, 0); /* If the key is a range, make a copy since map_char_table modifies it in place. */ if (CONSP (key)) key = Fcons (XCAR (key), XCDR (key)); - map_keymap_item (fun, XSAVE_OBJECT (args, 2), key, - val, XSAVE_POINTER (args, 1)); + union map_keymap *md = XINTPTR (args); + map_keymap_item (md->s.fun, md->s.args, key, val, md->s.data); } } @@ -594,9 +603,11 @@ map_keymap_internal (Lisp_Object map, } } else if (CHAR_TABLE_P (binding)) - map_char_table (map_keymap_char_table_item, Qnil, binding, - make_save_funcptr_ptr_obj ((voidfuncptr) fun, data, - args)); + { + union map_keymap mapdata = {{fun, args, data}}; + map_char_table (map_keymap_char_table_item, Qnil, binding, + make_pointer_integer (&mapdata)); + } } return tail; -- 2.17.1