unbind_to performance tuning
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 30 Jun 2018 00:07:38 +0000 (17:07 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 30 Jun 2018 00:07:57 +0000 (17:07 -0700)
* 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.

15 files changed:
src/alloc.c
src/coding.c
src/dispnew.c
src/editfns.c
src/eval.c
src/fileio.c
src/indent.c
src/keymap.c
src/lread.c
src/minibuf.c
src/sysdep.c
src/textprop.c
src/window.c
src/xdisp.c
src/xselect.c

index cc846fd38ee2e185e8d3049b01c6a7558cabac67..8764591336e838a27e292258146898bbff30fecb 100644 (file)
@@ -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
index 32a9df1c533167c1e2ac701c6811bea9c2331acb..8ce902b06d5cc499c97572af87a69ed9995eb235 100644 (file)
@@ -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));
 }
 
index 46e0c83ef6ab71529450c1cf0a5241f78bbc3da7..fc6f9e22632658d5e8d0b933de1bbb2bd2eeacaa 100644 (file)
@@ -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);
 }
 
 
index 88dfba1f9102317876743d8ad5972b251f41d8dc..efe83e811ba80666aeb10da8c75f043d7708e3f8 100644 (file)
@@ -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);
 }
 
 
index 9e0fabdcfba3415e22c3a6f0e024f6dfb144329b..c16a267bc5e6828e6033e2810276f92d0d6e53ba 100644 (file)
@@ -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)
index 7f678dd82163187ee25dcf6b6288dcb86335312a..5a1c7ae10e5bb4f45b127c104060bf274c5e687d 100644 (file)
@@ -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,
index 9c751bc30b5f8c1a200c07248ceafd632758a8e0..a86db71642e124a9c8759047958a9760ad025ab8 100644 (file)
@@ -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));
 }
 
 
index 982c014f01f358478043f128c9f6bd3fa9c8a0d1..fcee788e6f92d093bed108dca90404ba93e7e497 100644 (file)
@@ -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.  */
index 4229ff568bee5416c11cd0ed2a7d20db50bc66cf..d4e5be21b4be34a1624e4d4492c3617083f57286 100644 (file)
@@ -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",
index e18c99bef28f78a44cb89e1c87fcc759fda1f0be..abc4866380288b80713b6b007807d953118ee4ff 100644 (file)
@@ -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);
 }
index c59034ce5c30373f3049aa11700496680cccd832..231b11614f43671c7e6dade2ed47b8e40b1b62a3 100644 (file)
@@ -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__
index 984f2e664061dfd526d3c1765eb60c905c329dff..f7e69f30ea653df8d2b424ac0270cf8aef391876 100644 (file)
@@ -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;
index 81fd7f2b47793129d432a5027af40f5252c9e7fb..a97f1dd3efbdcf27b79044f44608ff6ee38a6755 100644 (file)
@@ -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);
 }
 \f
 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 2, "^P\np",
index 3406c2fb466931a6d0039c9fb4a510d4e0d804ec..e383b3b0d16e4a7a4a0c9561be085dd6fb629036 100644 (file)
@@ -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 "-";
index ecf59df2943e66bbfc0e9551cd7ab7ab66e53322..1f51be4c522c177e94a50a1d89f6d5930de3198a 100644 (file)
@@ -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