emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 2e28118: unbind_to performance tuning


From: Paul Eggert
Subject: [Emacs-diffs] master 2e28118: unbind_to performance tuning
Date: Fri, 29 Jun 2018 20:08:03 -0400 (EDT)

branch: master
commit 2e2811865f0adb6658a87d3581a2dc3a9022f451
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    unbind_to performance tuning
    
    * src/alloc.c (which_symbols):
    * src/dispnew.c (Fredisplay):
    * src/editfns.c (Fsubst_char_in_region):
    * src/fileio.c (Fdo_auto_save):
    * src/indent.c (Fvertical_motion):
    * src/keymap.c (Fcurrent_active_maps):
    * src/lread.c (Feval_buffer):
    * src/minibuf.c (get_minibuffer):
    * src/sysdep.c (system_process_attributes):
    * src/textprop.c (Fnext_single_char_property_change)
    (Fprevious_single_char_property_change):
    * src/window.c (Fscroll_other_window, Fscroll_other_window_down):
    * src/xdisp.c (Fformat_mode_line):
    Help the compiler eliminate tail recursion in call to unbind_to.
    * src/coding.c (decode_coding_gap):
    Omit unnecessary unbind_to, as we’re about to call unbind_to anyway.
    * src/coding.c (Fread_coding_system):
    * src/eval.c (eval_sub):
    * src/xdisp.c (handle_single_display_spec, decode_mode_spec):
    * src/xselect.c (x_get_local_selection):
    Avoid need to save a machine register when calling unbind_to.
    * src/minibuf.c (Ftry_completion, Fall_completions):
    Omit unnecessary assignment.
---
 src/alloc.c    |  3 +--
 src/coding.c   |  4 +---
 src/dispnew.c  |  3 +--
 src/editfns.c  |  3 +--
 src/eval.c     |  2 +-
 src/fileio.c   |  3 +--
 src/indent.c   |  4 +---
 src/keymap.c   |  4 +---
 src/lread.c    |  4 +---
 src/minibuf.c  | 41 ++++++++++++++++++++---------------------
 src/sysdep.c   |  3 +--
 src/textprop.c |  4 ++--
 src/window.c   |  6 ++----
 src/xdisp.c    |  9 ++++-----
 src/xselect.c  |  2 +-
 15 files changed, 39 insertions(+), 56 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index cc846fd..8764591 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -7206,8 +7206,7 @@ which_symbols (Lisp_Object obj, EMACS_INT find_max)
      }
 
   out:
-   unbind_to (gc_count, Qnil);
-   return found;
+   return unbind_to (gc_count, found);
 }
 
 #ifdef SUSPICIOUS_OBJECT_CHECKING
diff --git a/src/coding.c b/src/coding.c
index 32a9df1..8ce902b 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -8005,7 +8005,6 @@ decode_coding_gap (struct coding_system *coding,
       ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;
       Lisp_Object val;
       Lisp_Object undo_list = BVAR (current_buffer, undo_list);
-      ptrdiff_t count1 = SPECPDL_INDEX ();
 
       record_unwind_protect (coding_restore_undo_list,
                             Fcons (undo_list, Fcurrent_buffer ()));
@@ -8016,7 +8015,6 @@ decode_coding_gap (struct coding_system *coding,
       CHECK_NATNUM (val);
       coding->produced_char += Z - prev_Z;
       coding->produced += Z_BYTE - prev_Z_BYTE;
-      unbind_to (count1, Qnil);
     }
 
   unbind_to (count, Qnil);
@@ -8545,7 +8543,7 @@ are lower-case).  */)
   val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil,
                          Qt, Qnil, Qcoding_system_history,
                          default_coding_system, Qnil);
-  unbind_to (count, Qnil);
+  val = unbind_to (count, val);
   return (SCHARS (val) == 0 ? Qnil : Fintern (val, Qnil));
 }
 
diff --git a/src/dispnew.c b/src/dispnew.c
index 46e0c83..fc6f9e2 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5828,8 +5828,7 @@ immediately by pending input.  */)
   if (!NILP (force) && !redisplay_dont_pause)
     specbind (Qredisplay_dont_pause, Qt);
   redisplay_preserve_echo_area (2);
-  unbind_to (count, Qnil);
-  return Qt;
+  return unbind_to (count, Qt);
 }
 
 
diff --git a/src/editfns.c b/src/editfns.c
index 88dfba1..efe83e8 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3531,8 +3531,7 @@ Both characters must have the same length of multi-byte 
form.  */)
       update_compositions (changed, last_changed, CHECK_ALL);
     }
 
-  unbind_to (count, Qnil);
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 
 
diff --git a/src/eval.c b/src/eval.c
index 9e0fabd..c16a267 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2366,7 +2366,7 @@ eval_sub (Lisp_Object form)
          specbind (Qlexical_binding,
                    NILP (Vinternal_interpreter_environment) ? Qnil : Qt);
          exp = apply1 (Fcdr (fun), original_args);
-         unbind_to (count1, Qnil);
+         exp = unbind_to (count1, exp);
          val = eval_sub (exp);
        }
       else if (EQ (funcar, Qlambda)
diff --git a/src/fileio.c b/src/fileio.c
index 7f678dd..5a1c7ae 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5767,8 +5767,7 @@ A non-nil CURRENT-ONLY argument means save only current 
buffer.  */)
   Vquit_flag = oquit;
 
   /* This restores the message-stack status.  */
-  unbind_to (count, Qnil);
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 
 DEFUN ("set-buffer-auto-saved", Fset_buffer_auto_saved,
diff --git a/src/indent.c b/src/indent.c
index 9c751bc..a86db71 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -2356,9 +2356,7 @@ whether or not it is currently displayed in some window.  
*/)
       bidi_unshelve_cache (itdata, 0);
     }
 
-  unbind_to (count, Qnil);
-
-  return make_number (it.vpos);
+  return unbind_to (count, make_number (it.vpos));
 }
 
 
diff --git a/src/keymap.c b/src/keymap.c
index 982c014..fcee788 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1608,9 +1608,7 @@ like in the respective argument of `key-binding'.  */)
        keymaps = Fcons (otlp, keymaps);
     }
 
-  unbind_to (count, Qnil);
-
-  return keymaps;
+  return unbind_to (count, keymaps);
 }
 
 /* GC is possible in this function if it autoloads a keymap.  */
diff --git a/src/lread.c b/src/lread.c
index 4229ff5..d4e5be2 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2143,9 +2143,7 @@ This function preserves the position of point.  */)
   BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
   readevalloop (buf, 0, filename,
                !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
-  unbind_to (count, Qnil);
-
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 
 DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
diff --git a/src/minibuf.c b/src/minibuf.c
index e18c99b..abc4866 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -755,7 +755,7 @@ get_minibuffer (EMACS_INT depth)
        call0 (intern ("minibuffer-inactive-mode"));
       else
         Fkill_all_local_variables ();
-      unbind_to (count, Qnil);
+      buf = unbind_to (count, buf);
     }
 
   return buf;
@@ -1274,11 +1274,12 @@ is used to further constrain the set of candidates.  */)
            for (regexps = Vcompletion_regexp_list; CONSP (regexps);
                 regexps = XCDR (regexps))
              {
-               if (bindcount < 0) {
-                 bindcount = SPECPDL_INDEX ();
-                 specbind (Qcase_fold_search,
-                           completion_ignore_case ? Qt : Qnil);
-               }
+               if (bindcount < 0)
+                 {
+                   bindcount = SPECPDL_INDEX ();
+                   specbind (Qcase_fold_search,
+                             completion_ignore_case ? Qt : Qnil);
+                 }
                tem = Fstring_match (XCAR (regexps), eltstring, zero);
                if (NILP (tem))
                  break;
@@ -1377,10 +1378,8 @@ is used to further constrain the set of candidates.  */)
        }
     }
 
-  if (bindcount >= 0) {
+  if (bindcount >= 0)
     unbind_to (bindcount, Qnil);
-    bindcount = -1;
-  }
 
   if (NILP (bestmatch))
     return Qnil;               /* No completions found.  */
@@ -1534,11 +1533,12 @@ with a space are ignored unless STRING itself starts 
with a space.  */)
            for (regexps = Vcompletion_regexp_list; CONSP (regexps);
                 regexps = XCDR (regexps))
              {
-               if (bindcount < 0) {
-                 bindcount = SPECPDL_INDEX ();
-                 specbind (Qcase_fold_search,
-                           completion_ignore_case ? Qt : Qnil);
-               }
+               if (bindcount < 0)
+                 {
+                   bindcount = SPECPDL_INDEX ();
+                   specbind (Qcase_fold_search,
+                             completion_ignore_case ? Qt : Qnil);
+                 }
                tem = Fstring_match (XCAR (regexps), eltstring, zero);
                if (NILP (tem))
                  break;
@@ -1556,10 +1556,11 @@ with a space are ignored unless STRING itself starts 
with a space.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
-                 if (bindcount >= 0) {
-                   unbind_to (bindcount, Qnil);
-                   bindcount = -1;
-                 }
+                 if (bindcount >= 0)
+                   {
+                     unbind_to (bindcount, Qnil);
+                     bindcount = -1;
+                   }
                  tem = type == 3
                    ? call2 (predicate, elt,
                             HASH_VALUE (XHASH_TABLE (collection), idx - 1))
@@ -1572,10 +1573,8 @@ with a space are ignored unless STRING itself starts 
with a space.  */)
        }
     }
 
-  if (bindcount >= 0) {
+  if (bindcount >= 0)
     unbind_to (bindcount, Qnil);
-    bindcount = -1;
-  }
 
   return Fnreverse (allmatches);
 }
diff --git a/src/sysdep.c b/src/sysdep.c
index c59034c..231b116 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3592,8 +3592,7 @@ system_process_attributes (Lisp_Object pid)
                                                  Vlocale_coding_system, 0);
       attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
     }
-  unbind_to (count, Qnil);
-  return attrs;
+  return unbind_to (count, attrs);
 }
 
 #elif defined __FreeBSD__
diff --git a/src/textprop.c b/src/textprop.c
index 984f2e6..f7e69f3 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -826,7 +826,7 @@ last valid position in OBJECT.  */)
              break;
          }
 
-      unbind_to (count, Qnil);
+      position = unbind_to (count, position);
     }
 
   return position;
@@ -920,7 +920,7 @@ first valid position in OBJECT.  */)
            }
        }
 
-      unbind_to (count, Qnil);
+      position = unbind_to (count, position);
     }
 
   return position;
diff --git a/src/window.c b/src/window.c
index 81fd7f2..a97f1dd 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5771,8 +5771,7 @@ which see.  */)
 {
   ptrdiff_t count = SPECPDL_INDEX ();
   scroll_command (Fother_window_for_scrolling (), arg, 1);
-  unbind_to (count, Qnil);
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 
 DEFUN ("scroll-other-window-down", Fscroll_other_window_down,
@@ -5783,8 +5782,7 @@ For more details, see the documentation for 
`scroll-other-window'.  */)
 {
   ptrdiff_t count = SPECPDL_INDEX ();
   scroll_command (Fother_window_for_scrolling (), arg, -1);
-  unbind_to (count, Qnil);
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 
 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "^P\np",
diff --git a/src/xdisp.c b/src/xdisp.c
index 3406c2f..e383b3b 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -4937,7 +4937,7 @@ handle_single_display_spec (struct it *it, Lisp_Object 
spec, Lisp_Object object,
       specbind (Qposition, make_number (CHARPOS (*position)));
       specbind (Qbuffer_position, make_number (bufpos));
       form = safe_eval (form);
-      unbind_to (count, Qnil);
+      form = unbind_to (count, form);
     }
 
   if (NILP (form))
@@ -5000,7 +5000,7 @@ handle_single_display_spec (struct it *it, Lisp_Object 
spec, Lisp_Object object,
 
                  specbind (Qheight, face->lface[LFACE_HEIGHT_INDEX]);
                  value = safe_eval (it->font_height);
-                 unbind_to (count, Qnil);
+                 value = unbind_to (count, value);
 
                  if (NUMBERP (value))
                    new_height = XFLOATINT (value);
@@ -24183,8 +24183,7 @@ are the selected window and the WINDOW's buffer).  */)
                        empty_unibyte_string);
     }
 
-  unbind_to (count, Qnil);
-  return str;
+  return unbind_to (count, str);
 }
 
 /* Write a null-terminated, right justified decimal representation of
@@ -24804,7 +24803,7 @@ decode_mode_spec (struct window *w, register int c, int 
field_width,
        if (STRINGP (curdir))
          val = call1 (intern ("file-remote-p"), curdir);
 
-       unbind_to (count, Qnil);
+       val = unbind_to (count, val);
 
        if (NILP (val))
          return "-";
diff --git a/src/xselect.c b/src/xselect.c
index ecf59df..1f51be4 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -387,7 +387,7 @@ x_get_local_selection (Lisp_Object selection_symbol, 
Lisp_Object target_type,
                       XCAR (XCDR (local_value)));
       else
        value = Qnil;
-      unbind_to (count, Qnil);
+      value = unbind_to (count, value);
     }
 
   /* Make sure this value is of a type that we could transmit



reply via email to

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