emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 12fd59b 03/10: Avoid Lisp_Misc allocation if C stac


From: Paul Eggert
Subject: [Emacs-diffs] master 12fd59b 03/10: Avoid Lisp_Misc allocation if C stack suffices
Date: Thu, 14 Jun 2018 20:15:24 -0400 (EDT)

branch: master
commit 12fd59bba0b04fb6727f4fa54e3305a65fae1d44
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    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 | 29 ++++++++++++++++++-----------
 src/keymap.c | 26 +++++++++++++++++++-------
 2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/src/fileio.c b/src/fileio.c
index 47c5fec..7f678dd 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -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
+{
+  struct
+  {
+    int fd;
+    ptrdiff_t inserted, trytry;
+  } s;
+  GCALIGNED_UNION
+};
+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,
                                ((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);
 }
 
@@ -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
-             (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 c8cc933..982c014 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -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
+{
+  struct
+  {
+    map_keymap_function_t fun;
+    Lisp_Object args;
+    void *data;
+  } s;
+  GCALIGNED_UNION
+};
+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->s.fun, md->s.args, key, val, md->s.data);
     }
 }
 
@@ -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,
-                                                  args));
+       {
+         union map_keymap mapdata = {{fun, args, data}};
+         map_char_table (map_keymap_char_table_item, Qnil, binding,
+                         make_pointer_integer (&mapdata));
+       }
     }
 
   return tail;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]