From: David Vazquez Date: Sun, 10 Feb 2013 20:30:10 +0000 (+0000) Subject: Avoid type-checking in constant number arguments to arithmetic functions X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=e1222144f4f104f88503c2e42e9177a8f7726f53;p=jscl.git Avoid type-checking in constant number arguments to arithmetic functions --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 2777a90..8db7c46 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1930,16 +1930,18 @@ (unless (consp args) (error "ARGS must be a non-empty list")) (let ((counter 0) - (variables '()) + (fargs '()) (prelude "")) (dolist (x args) - (let ((v (code "x" (incf counter)))) - (push v variables) - (concatf prelude - (code "var " v " = " (ls-compile x) ";" *newline* - "if (typeof " v " !== 'number') throw 'Not a number!';" - *newline*)))) - (js!selfcall prelude (funcall function (reverse variables))))) + (if (numberp x) + (push (integer-to-string x) fargs) + (let ((v (code "x" (incf counter)))) + (push v fargs) + (concatf prelude + (code "var " v " = " (ls-compile x) ";" *newline* + "if (typeof " v " !== 'number') throw 'Not a number!';" + *newline*))))) + (js!selfcall prelude (funcall function (reverse fargs))))) (defmacro variable-arity (args &body body) @@ -1947,7 +1949,7 @@ (error "Bad usage of VARIABLE-ARITY, you must pass a symbol")) `(variable-arity-call ,args (lambda (,args) - (concat "return " ,@body ";" *newline*)))) + (code "return " ,@body ";" *newline*)))) (defun num-op-num (x op y) (type-check (("x" "number" x) ("y" "number" y))