aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd2022-01-18 13:10:05 +0100
committerMattias EngdegÄrd2022-03-13 17:51:49 +0100
commit267f41c7ce1e02f392b57aa338d387e7627df184 (patch)
tree72b4f486c5a429fd462269b37575c55d065f2b57 /src/bytecode.c
parent35f75b63b51660190b48020c048701ae8553ea1f (diff)
downloademacs-267f41c7ce1e02f392b57aa338d387e7627df184.tar.gz
emacs-267f41c7ce1e02f392b57aa338d387e7627df184.zip
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.
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 286a8d675d4..7c390c0d40e 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -324,9 +324,8 @@ If the third argument is incorrect, Emacs may crash. */)
324 the original unibyte form. */ 324 the original unibyte form. */
325 bytestr = Fstring_as_unibyte (bytestr); 325 bytestr = Fstring_as_unibyte (bytestr);
326 } 326 }
327 pin_string (bytestr); // Bytecode must be immovable. 327 Lisp_Object args[] = {0, bytestr, vector, maxdepth};
328 328 return exec_byte_code (Fmake_byte_code (4, args), 0, 0, NULL);
329 return exec_byte_code (bytestr, vector, maxdepth, 0, 0, NULL);
330} 329}
331 330
332static void 331static void
@@ -335,24 +334,26 @@ bcall0 (Lisp_Object f)
335 Ffuncall (1, &f); 334 Ffuncall (1, &f);
336} 335}
337 336
338/* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and 337/* Execute the byte-code in FUN. ARGS_TEMPLATE is the function arity
339 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect, 338 encoded as an integer (the one in FUN is ignored), and ARGS, of
340 emacs may crash!). ARGS_TEMPLATE is the function arity encoded as an 339 size NARGS, should be a vector of the actual arguments. The
341 integer, and ARGS, of size NARGS, should be a vector of the actual 340 arguments in ARGS are pushed on the stack according to
342 arguments. The arguments in ARGS are pushed on the stack according 341 ARGS_TEMPLATE before executing FUN. */
343 to ARGS_TEMPLATE before executing BYTESTR. */
344 342
345Lisp_Object 343Lisp_Object
346exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, 344exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
347 ptrdiff_t args_template, ptrdiff_t nargs, Lisp_Object *args) 345 ptrdiff_t nargs, Lisp_Object *args)
348{ 346{
349#ifdef BYTE_CODE_METER 347#ifdef BYTE_CODE_METER
350 int volatile this_op = 0; 348 int volatile this_op = 0;
351#endif 349#endif
352 350
351 Lisp_Object bytestr = AREF (fun, COMPILED_BYTECODE);
352
353 eassert (!STRING_MULTIBYTE (bytestr)); 353 eassert (!STRING_MULTIBYTE (bytestr));
354 eassert (string_immovable_p (bytestr)); 354 eassert (string_immovable_p (bytestr));
355 355 Lisp_Object vector = AREF (fun, COMPILED_CONSTANTS);
356 Lisp_Object maxdepth = AREF (fun, COMPILED_STACK_DEPTH);
356 ptrdiff_t const_length = ASIZE (vector); 357 ptrdiff_t const_length = ASIZE (vector);
357 ptrdiff_t bytestr_length = SCHARS (bytestr); 358 ptrdiff_t bytestr_length = SCHARS (bytestr);
358 Lisp_Object *vectorp = XVECTOR (vector)->contents; 359 Lisp_Object *vectorp = XVECTOR (vector)->contents;
@@ -657,10 +658,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
657 // No autoloads. 658 // No autoloads.
658 && (bytecode = AREF (fun, COMPILED_BYTECODE), 659 && (bytecode = AREF (fun, COMPILED_BYTECODE),
659 !CONSP (bytecode))) 660 !CONSP (bytecode)))
660 val = exec_byte_code (bytecode, 661 val = exec_byte_code (fun, XFIXNUM (template), numargs, args);
661 AREF (fun, COMPILED_CONSTANTS),
662 AREF (fun, COMPILED_STACK_DEPTH),
663 XFIXNUM (template), numargs, args);
664 else if (SUBRP (fun) && !SUBR_NATIVE_COMPILED_DYNP (fun)) 662 else if (SUBRP (fun) && !SUBR_NATIVE_COMPILED_DYNP (fun))
665 val = funcall_subr (XSUBR (fun), numargs, args); 663 val = funcall_subr (XSUBR (fun), numargs, args);
666 else 664 else