Commit 12fd59bb authored by Paul Eggert's avatar Paul Eggert

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.
parent ef66660c
......@@ -3362,20 +3362,27 @@ 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
int fd;
ptrdiff_t inserted, trytry;
} s;
verify (alignof (union read_non_regular) % GCALIGNMENT == 0);
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,
+ XSAVE_INTEGER (state, 1)),
XSAVE_INTEGER (state, 2));
/* Fast recycle this object for the likely next call. */
free_misc (state);
+ data->s.inserted),
return make_number (nbytes);
......@@ -4230,9 +4237,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
make_save_int_int_int (fd, inserted, trytry),
(read_non_regular, make_pointer_integer (&data),
Qerror, read_non_regular_quit);
if (NILP (nbytes))
......@@ -546,19 +546,29 @@ map_keymap_item (map_keymap_function_t fun, Lisp_Object args, Lisp_Object key, L
(*fun) (key, val, args, data);
union map_keymap
map_keymap_function_t fun;
Lisp_Object args;
void *data;
} s;
verify (alignof (union map_keymap) % GCALIGNMENT == 0);
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->, md->s.args, key, val, md->;
......@@ -594,9 +604,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,
union map_keymap mapdata = {{fun, args, data}};
map_char_table (map_keymap_char_table_item, Qnil, binding,
make_pointer_integer (&mapdata));
return tail;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment