diff options
| author | Mattias EngdegÄrd | 2022-01-01 22:39:17 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2022-01-24 11:41:46 +0100 |
| commit | b3377e67a7b20a9a53aa2129b2c3951be67ad102 (patch) | |
| tree | e2e4f16271cb8fe3cb5a695282c76bc5914e5ab4 /src/bytecode.c | |
| parent | d05f387407858672ff0d10b963dbdeaf2a9163e0 (diff) | |
| download | emacs-b3377e67a7b20a9a53aa2129b2c3951be67ad102.tar.gz emacs-b3377e67a7b20a9a53aa2129b2c3951be67ad102.zip | |
Remove nil check in exec_byte_code
Since we pass no arguments to a non-lexbind bytecode function, we can
specify its arity as 0 instead of nil and save a test and branch.
* src/bytecode.c (Fbyte_code, exec_byte_code):
* src/eval.c (fetch_and_exec_byte_code, funcall_lambda):
* src/lisp.h:
Change the args_template parameter type to ptrdiff_t, since it is now
always a small integer, in exec_byte_code and
fetch_and_exec_byte_code, all callers adjusted.
Diffstat (limited to 'src/bytecode.c')
| -rw-r--r-- | src/bytecode.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 7a9966e20ef..8e0f3d3e4b2 100644 --- a/src/bytecode.c +++ b/src/bytecode.c | |||
| @@ -333,7 +333,7 @@ If the third argument is incorrect, Emacs may crash. */) | |||
| 333 | } | 333 | } |
| 334 | pin_string (bytestr); // Bytecode must be immovable. | 334 | pin_string (bytestr); // Bytecode must be immovable. |
| 335 | 335 | ||
| 336 | return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL); | 336 | return exec_byte_code (bytestr, vector, maxdepth, 0, 0, NULL); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | static void | 339 | static void |
| @@ -344,15 +344,14 @@ bcall0 (Lisp_Object f) | |||
| 344 | 344 | ||
| 345 | /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and | 345 | /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and |
| 346 | MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect, | 346 | MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect, |
| 347 | emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp | 347 | emacs may crash!). ARGS_TEMPLATE is the function arity encoded as an |
| 348 | argument list (including &rest, &optional, etc.), and ARGS, of size | 348 | integer, and ARGS, of size NARGS, should be a vector of the actual |
| 349 | NARGS, should be a vector of the actual arguments. The arguments in | 349 | arguments. The arguments in ARGS are pushed on the stack according |
| 350 | ARGS are pushed on the stack according to ARGS_TEMPLATE before | 350 | to ARGS_TEMPLATE before executing BYTESTR. */ |
| 351 | executing BYTESTR. */ | ||
| 352 | 351 | ||
| 353 | Lisp_Object | 352 | Lisp_Object |
| 354 | exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, | 353 | exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, |
| 355 | Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) | 354 | ptrdiff_t args_template, ptrdiff_t nargs, Lisp_Object *args) |
| 356 | { | 355 | { |
| 357 | #ifdef BYTE_CODE_METER | 356 | #ifdef BYTE_CODE_METER |
| 358 | int volatile this_op = 0; | 357 | int volatile this_op = 0; |
| @@ -384,26 +383,25 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, | |||
| 384 | unsigned char const *pc = bytestr_data; | 383 | unsigned char const *pc = bytestr_data; |
| 385 | ptrdiff_t count = SPECPDL_INDEX (); | 384 | ptrdiff_t count = SPECPDL_INDEX (); |
| 386 | 385 | ||
| 387 | if (!NILP (args_template)) | 386 | /* ARGS_TEMPLATE is composed of bit fields: |
| 388 | { | 387 | bits 0..6 minimum number of arguments |
| 389 | eassert (FIXNUMP (args_template)); | 388 | bits 7 1 iff &rest argument present |
| 390 | ptrdiff_t at = XFIXNUM (args_template); | 389 | bits 8..14 maximum number of arguments */ |
| 391 | bool rest = (at & 128) != 0; | 390 | bool rest = (args_template & 128) != 0; |
| 392 | int mandatory = at & 127; | 391 | int mandatory = args_template & 127; |
| 393 | ptrdiff_t nonrest = at >> 8; | 392 | ptrdiff_t nonrest = args_template >> 8; |
| 394 | if (! (mandatory <= nargs && (rest || nargs <= nonrest))) | 393 | if (! (mandatory <= nargs && (rest || nargs <= nonrest))) |
| 395 | Fsignal (Qwrong_number_of_arguments, | 394 | Fsignal (Qwrong_number_of_arguments, |
| 396 | list2 (Fcons (make_fixnum (mandatory), make_fixnum (nonrest)), | 395 | list2 (Fcons (make_fixnum (mandatory), make_fixnum (nonrest)), |
| 397 | make_fixnum (nargs))); | 396 | make_fixnum (nargs))); |
| 398 | ptrdiff_t pushedargs = min (nonrest, nargs); | 397 | ptrdiff_t pushedargs = min (nonrest, nargs); |
| 399 | for (ptrdiff_t i = 0; i < pushedargs; i++, args++) | 398 | for (ptrdiff_t i = 0; i < pushedargs; i++, args++) |
| 400 | PUSH (*args); | 399 | PUSH (*args); |
| 401 | if (nonrest < nargs) | 400 | if (nonrest < nargs) |
| 402 | PUSH (Flist (nargs - nonrest, args)); | 401 | PUSH (Flist (nargs - nonrest, args)); |
| 403 | else | 402 | else |
| 404 | for (ptrdiff_t i = nargs - rest; i < nonrest; i++) | 403 | for (ptrdiff_t i = nargs - rest; i < nonrest; i++) |
| 405 | PUSH (Qnil); | 404 | PUSH (Qnil); |
| 406 | } | ||
| 407 | 405 | ||
| 408 | while (true) | 406 | while (true) |
| 409 | { | 407 | { |
| @@ -671,7 +669,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, | |||
| 671 | val = exec_byte_code (bytecode, | 669 | val = exec_byte_code (bytecode, |
| 672 | AREF (fun, COMPILED_CONSTANTS), | 670 | AREF (fun, COMPILED_CONSTANTS), |
| 673 | AREF (fun, COMPILED_STACK_DEPTH), | 671 | AREF (fun, COMPILED_STACK_DEPTH), |
| 674 | template, numargs, args); | 672 | XFIXNUM (template), numargs, args); |
| 675 | else if (SUBRP (fun) && !SUBR_NATIVE_COMPILED_DYNP (fun)) | 673 | else if (SUBRP (fun) && !SUBR_NATIVE_COMPILED_DYNP (fun)) |
| 676 | val = funcall_subr (XSUBR (fun), numargs, args); | 674 | val = funcall_subr (XSUBR (fun), numargs, args); |
| 677 | else | 675 | else |