Commit bc9cc21d authored by Paul Eggert's avatar Paul Eggert

func-arity minor improvements

* src/bytecode.c (get_byte_code_arity): Omit unnecessary
runtime test for integer argument, unless debugging.
Use EMACS_INT for Emacs integers.
* src/eval.c (Ffunc_arity): Omit unused locals.
Avoid side effects in ‘if’ expr.
(lambda_arity): Use bool for boolean, and EMACS_INT for Emacs ints.
parent efb18832
...@@ -1991,18 +1991,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, ...@@ -1991,18 +1991,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
Lisp_Object Lisp_Object
get_byte_code_arity (Lisp_Object args_template) get_byte_code_arity (Lisp_Object args_template)
{ {
if (INTEGERP (args_template)) eassert (NATNUMP (args_template));
{ EMACS_INT at = XINT (args_template);
ptrdiff_t at = XINT (args_template); bool rest = (at & 128) != 0;
bool rest = (at & 128) != 0; int mandatory = at & 127;
int mandatory = at & 127; EMACS_INT nonrest = at >> 8;
ptrdiff_t nonrest = at >> 8;
return Fcons (make_number (mandatory),
return Fcons (make_number (mandatory), rest ? Qmany : make_number (nonrest));
rest ? Qmany : make_number (nonrest));
}
else
error ("Unknown args template!");
} }
void void
......
...@@ -2946,7 +2946,6 @@ function with `&rest' args, or `unevalled' for a special form. */) ...@@ -2946,7 +2946,6 @@ function with `&rest' args, or `unevalled' for a special form. */)
Lisp_Object original; Lisp_Object original;
Lisp_Object funcar; Lisp_Object funcar;
Lisp_Object result; Lisp_Object result;
short minargs, maxargs;
original = function; original = function;
...@@ -2954,9 +2953,12 @@ function with `&rest' args, or `unevalled' for a special form. */) ...@@ -2954,9 +2953,12 @@ function with `&rest' args, or `unevalled' for a special form. */)
/* Optimize for no indirection. */ /* Optimize for no indirection. */
function = original; function = original;
if (SYMBOLP (function) && !NILP (function) if (SYMBOLP (function) && !NILP (function))
&& (function = XSYMBOL (function)->function, SYMBOLP (function))) {
function = indirect_function (function); function = XSYMBOL (function)->function;
if (SYMBOLP (function))
function = indirect_function (function);
}
if (SUBRP (function)) if (SUBRP (function))
result = Fsubr_arity (function); result = Fsubr_arity (function);
...@@ -2989,9 +2991,7 @@ function with `&rest' args, or `unevalled' for a special form. */) ...@@ -2989,9 +2991,7 @@ function with `&rest' args, or `unevalled' for a special form. */)
static Lisp_Object static Lisp_Object
lambda_arity (Lisp_Object fun) lambda_arity (Lisp_Object fun)
{ {
Lisp_Object val, syms_left, next; Lisp_Object syms_left;
ptrdiff_t minargs, maxargs;
bool optional;
if (CONSP (fun)) if (CONSP (fun))
{ {
...@@ -3018,17 +3018,18 @@ lambda_arity (Lisp_Object fun) ...@@ -3018,17 +3018,18 @@ lambda_arity (Lisp_Object fun)
else else
emacs_abort (); emacs_abort ();
minargs = maxargs = optional = 0; EMACS_INT minargs = 0, maxargs = 0;
bool optional = false;
for (; CONSP (syms_left); syms_left = XCDR (syms_left)) for (; CONSP (syms_left); syms_left = XCDR (syms_left))
{ {
next = XCAR (syms_left); Lisp_Object next = XCAR (syms_left);
if (!SYMBOLP (next)) if (!SYMBOLP (next))
xsignal1 (Qinvalid_function, fun); xsignal1 (Qinvalid_function, fun);
if (EQ (next, Qand_rest)) if (EQ (next, Qand_rest))
return Fcons (make_number (minargs), Qmany); return Fcons (make_number (minargs), Qmany);
else if (EQ (next, Qand_optional)) else if (EQ (next, Qand_optional))
optional = 1; optional = true;
else else
{ {
if (!optional) if (!optional)
...@@ -3043,7 +3044,6 @@ lambda_arity (Lisp_Object fun) ...@@ -3043,7 +3044,6 @@ lambda_arity (Lisp_Object fun)
return Fcons (make_number (minargs), make_number (maxargs)); return Fcons (make_number (minargs), make_number (maxargs));
} }
DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode, DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
1, 1, 0, 1, 1, 0,
doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */) doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment