emacs-diffs
[Top][All Lists]
Advanced

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

master 267f41c7ce 1/2: Simplify exec_byte_code arguments


From: Mattias Engdegård
Subject: master 267f41c7ce 1/2: Simplify exec_byte_code arguments
Date: Sun, 13 Mar 2022 12:58:58 -0400 (EDT)

branch: master
commit 267f41c7ce1e02f392b57aa338d387e7627df184
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Simplify exec_byte_code arguments
    
    Pass the function object and encoded arity, not the other components.
    This speeds up several call paths and is necessary for improvements to
    come.
    
    * src/bytecode.c (Fbyte_code): Make a new byte code object for
    execution.  This is slower but performance isn't critical here.
    (exec_byte_code): Retrieve components from the passed function.
    * src/eval.c (fetch_and_exec_byte_code):
    * src/lisp.h (exec_byte_code): Update signature.
---
 src/bytecode.c | 30 ++++++++++++++----------------
 src/eval.c     |  5 +----
 src/lisp.h     |  4 ++--
 3 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/bytecode.c b/src/bytecode.c
index 286a8d675d..7c390c0d40 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -324,9 +324,8 @@ If the third argument is incorrect, Emacs may crash.  */)
         the original unibyte form.  */
       bytestr = Fstring_as_unibyte (bytestr);
     }
-  pin_string (bytestr);  // Bytecode must be immovable.
-
-  return exec_byte_code (bytestr, vector, maxdepth, 0, 0, NULL);
+  Lisp_Object args[] = {0, bytestr, vector, maxdepth};
+  return exec_byte_code (Fmake_byte_code (4, args), 0, 0, NULL);
 }
 
 static void
@@ -335,24 +334,26 @@ bcall0 (Lisp_Object f)
   Ffuncall (1, &f);
 }
 
-/* Execute the byte-code in BYTESTR.  VECTOR is the constant vector, and
-   MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
-   emacs may crash!).  ARGS_TEMPLATE is the function arity encoded as an
-   integer, and ARGS, of size NARGS, should be a vector of the actual
-   arguments.  The arguments in ARGS are pushed on the stack according
-   to ARGS_TEMPLATE before executing BYTESTR.  */
+/* Execute the byte-code in FUN.  ARGS_TEMPLATE is the function arity
+   encoded as an integer (the one in FUN is ignored), and ARGS, of
+   size NARGS, should be a vector of the actual arguments.  The
+   arguments in ARGS are pushed on the stack according to
+   ARGS_TEMPLATE before executing FUN.  */
 
 Lisp_Object
-exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
-               ptrdiff_t args_template, ptrdiff_t nargs, Lisp_Object *args)
+exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
+               ptrdiff_t nargs, Lisp_Object *args)
 {
 #ifdef BYTE_CODE_METER
   int volatile this_op = 0;
 #endif
 
+  Lisp_Object bytestr = AREF (fun, COMPILED_BYTECODE);
+
   eassert (!STRING_MULTIBYTE (bytestr));
   eassert (string_immovable_p (bytestr));
-
+  Lisp_Object vector = AREF (fun, COMPILED_CONSTANTS);
+  Lisp_Object maxdepth = AREF (fun, COMPILED_STACK_DEPTH);
   ptrdiff_t const_length = ASIZE (vector);
   ptrdiff_t bytestr_length = SCHARS (bytestr);
   Lisp_Object *vectorp = XVECTOR (vector)->contents;
@@ -657,10 +658,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, 
Lisp_Object maxdepth,
                // No autoloads.
                && (bytecode = AREF (fun, COMPILED_BYTECODE),
                    !CONSP (bytecode)))
-             val = exec_byte_code (bytecode,
-                                   AREF (fun, COMPILED_CONSTANTS),
-                                   AREF (fun, COMPILED_STACK_DEPTH),
-                                   XFIXNUM (template), numargs, args);
+             val = exec_byte_code (fun, XFIXNUM (template), numargs, args);
            else if (SUBRP (fun) && !SUBR_NATIVE_COMPILED_DYNP (fun))
              val = funcall_subr (XSUBR (fun), numargs, args);
            else
diff --git a/src/eval.c b/src/eval.c
index b747d2cbb6..b1c1a8c676 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3105,10 +3105,7 @@ fetch_and_exec_byte_code (Lisp_Object fun, ptrdiff_t 
args_template,
   if (CONSP (AREF (fun, COMPILED_BYTECODE)))
     Ffetch_bytecode (fun);
 
-  return exec_byte_code (AREF (fun, COMPILED_BYTECODE),
-                        AREF (fun, COMPILED_CONSTANTS),
-                        AREF (fun, COMPILED_STACK_DEPTH),
-                        args_template, nargs, args);
+  return exec_byte_code (fun, args_template, nargs, args);
 }
 
 static Lisp_Object
diff --git a/src/lisp.h b/src/lisp.h
index 0b649a92f5..5e3590675d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4852,8 +4852,8 @@ extern int read_bytecode_char (bool);
 
 /* Defined in bytecode.c.  */
 extern void syms_of_bytecode (void);
-extern Lisp_Object exec_byte_code (Lisp_Object, Lisp_Object, Lisp_Object,
-                                  ptrdiff_t, ptrdiff_t, Lisp_Object *);
+extern Lisp_Object exec_byte_code (Lisp_Object, ptrdiff_t,
+                                  ptrdiff_t, Lisp_Object *);
 extern Lisp_Object get_byte_code_arity (Lisp_Object);
 
 /* Defined in macros.c.  */



reply via email to

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