aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorPaul Eggert2020-05-19 23:22:40 -0700
committerPaul Eggert2020-05-19 23:25:16 -0700
commitf0b0105d913a94c66f230874c9269b19dbbc83bd (patch)
tree21180d9cd9266d18187e8dd4de487eed950efa14 /src/bytecode.c
parent5352bda4eeb7415ad2bda5d74e007b4f36021e68 (diff)
downloademacs-f0b0105d913a94c66f230874c9269b19dbbc83bd.tar.gz
emacs-f0b0105d913a94c66f230874c9269b19dbbc83bd.zip
Hoist some byte-code checking out of eval
Check Lisp_Compiled objects better as they’re created, so that the byte-code interpreter needn’t do the checks each time it executes them. This improved performance of ‘make compile-always’ by 1.5% on my platform. Also, improve the quality of the (still-incomplete) checks, as this is more practical now that they’re done less often. * src/alloc.c (make_byte_code): Remove. All uses removed. (Fmake_byte_code): Put a better (though still incomplete) check here instead. Simplify by using Fvector instead of make_uninit_vector followed by memcpy, and by using XSETPVECTYPE instead of make_byte_code followed by XSETCOMPILED. * src/bytecode.c (Fbyte_code): Do sanity check and conditional translation to unibyte here instead of each time the function is executed. (exec_byte_code): Omit no-longer-necessary sanity and unibyte checking. Use SCHARS instead of SBYTES where either will do, as SCHARS is faster. * src/eval.c (fetch_and_exec_byte_code): New function. (funcall_lambda): Use it. (funcall_lambda, lambda_arity, Ffetch_bytecode): Omit no-longer-necessary sanity checks. (Ffetch_bytecode): Add sanity check if actually fetching. * src/lisp.h (XSETCOMPILED): Remove. All uses removed. * src/lread.c (read1): Check byte-code objects more thoroughly, albeit still incompletely, and do translation to unibyte here instead of each time the function is executed. (read1): Use XSETPVECYPE instead of make_byte_code. (read_vector): Omit no-longer-necessary sanity check.
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 3c90544f3f2..5ac30aa1010 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -319,6 +319,19 @@ the third, MAXDEPTH, the maximum stack depth used in this function.
319If the third argument is incorrect, Emacs may crash. */) 319If the third argument is incorrect, Emacs may crash. */)
320 (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth) 320 (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth)
321{ 321{
322 if (! (STRINGP (bytestr) && VECTORP (vector) && FIXNATP (maxdepth)))
323 error ("Invalid byte-code");
324
325 if (STRING_MULTIBYTE (bytestr))
326 {
327 /* BYTESTR must have been produced by Emacs 20.2 or earlier
328 because it produced a raw 8-bit string for byte-code and now
329 such a byte-code string is loaded as multibyte with raw 8-bit
330 characters converted to multibyte form. Convert them back to
331 the original unibyte form. */
332 bytestr = Fstring_as_unibyte (bytestr);
333 }
334
322 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL); 335 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
323} 336}
324 337
@@ -344,21 +357,10 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
344 int volatile this_op = 0; 357 int volatile this_op = 0;
345#endif 358#endif
346 359
347 CHECK_STRING (bytestr); 360 eassert (!STRING_MULTIBYTE (bytestr));
348 CHECK_VECTOR (vector);
349 CHECK_FIXNAT (maxdepth);
350 361
351 ptrdiff_t const_length = ASIZE (vector); 362 ptrdiff_t const_length = ASIZE (vector);
352 363 ptrdiff_t bytestr_length = SCHARS (bytestr);
353 if (STRING_MULTIBYTE (bytestr))
354 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
355 because they produced a raw 8-bit string for byte-code and now
356 such a byte-code string is loaded as multibyte while raw 8-bit
357 characters converted to multibyte form. Thus, now we must
358 convert them back to the originally intended unibyte form. */
359 bytestr = Fstring_as_unibyte (bytestr);
360
361 ptrdiff_t bytestr_length = SBYTES (bytestr);
362 Lisp_Object *vectorp = XVECTOR (vector)->contents; 364 Lisp_Object *vectorp = XVECTOR (vector)->contents;
363 365
364 unsigned char quitcounter = 1; 366 unsigned char quitcounter = 1;