mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 02:20:21 -08:00
Use 'any' and 'all' to simplify parts of the byte-compiler
* lisp/emacs-lisp/byte-opt.el (byte-opt--nary-comparison) (byte-optimize-constant-args, byte-optimize-member) (byte-optimize-append): * lisp/emacs-lisp/bytecomp.el (byte-compile-warnings) (byte-compile-out-toplevel): * lisp/emacs-lisp/cconv.el (cconv-convert): Replace various hand-written 'any' and 'all' expressions with calls to the new functions, for readability and speed.
This commit is contained in:
parent
4a39e46d9c
commit
bcc88bc5c2
3 changed files with 27 additions and 34 deletions
|
|
@ -1005,19 +1005,19 @@ There can be multiple entries for the same NAME if it has several aliases.")
|
|||
(let* ((op (car form))
|
||||
(bindings nil)
|
||||
(rev-args nil))
|
||||
(if (memq nil (mapcar #'macroexp-copyable-p (cddr form)))
|
||||
;; At least one arg beyond the first is non-constant non-variable:
|
||||
;; create temporaries for all args to guard against side-effects.
|
||||
;; The optimizer will eliminate trivial bindings later.
|
||||
(let ((i 1))
|
||||
(dolist (arg (cdr form))
|
||||
(let ((var (make-symbol (format "arg%d" i))))
|
||||
(push var rev-args)
|
||||
(push (list var arg) bindings)
|
||||
(setq i (1+ i)))))
|
||||
;; All args beyond the first are copyable: no temporary variables
|
||||
;; required.
|
||||
(setq rev-args (reverse (cdr form))))
|
||||
(if (all #'macroexp-copyable-p (cddr form))
|
||||
;; All args beyond the first are copyable: no temporary variables
|
||||
;; required.
|
||||
(setq rev-args (reverse (cdr form)))
|
||||
;; At least one arg beyond the first is non-constant non-variable:
|
||||
;; create temporaries for all args to guard against side-effects.
|
||||
;; The optimizer will eliminate trivial bindings later.
|
||||
(let ((i 1))
|
||||
(dolist (arg (cdr form))
|
||||
(let ((var (make-symbol (format "arg%d" i))))
|
||||
(push var rev-args)
|
||||
(push (list var arg) bindings)
|
||||
(setq i (1+ i))))))
|
||||
(let ((prev (car rev-args))
|
||||
(exprs nil))
|
||||
(dolist (arg (cdr rev-args))
|
||||
|
|
@ -1030,14 +1030,11 @@ There can be multiple entries for the same NAME if it has several aliases.")
|
|||
(t form))))
|
||||
|
||||
(defun byte-optimize-constant-args (form)
|
||||
(let ((rest (cdr form)))
|
||||
(while (and rest (macroexp-const-p (car rest)))
|
||||
(setq rest (cdr rest)))
|
||||
(if rest
|
||||
form
|
||||
(if (all #'macroexp-const-p (cdr form))
|
||||
(condition-case ()
|
||||
(list 'quote (eval form t))
|
||||
(error form)))))
|
||||
(error form))
|
||||
form))
|
||||
|
||||
(defun byte-optimize-identity (form)
|
||||
(if (and (cdr form) (null (cdr (cdr form))))
|
||||
|
|
@ -1099,11 +1096,9 @@ See Info node `(elisp) Integer Basics'."
|
|||
(and (macroexp-const-p arg2)
|
||||
(let ((listval (byteopt--eval-const arg2)))
|
||||
(and (listp listval)
|
||||
(not (memq nil (mapcar
|
||||
(lambda (o)
|
||||
(or (symbolp o)
|
||||
(byte-optimize--fixnump o)))
|
||||
listval))))))))
|
||||
(all (lambda (o)
|
||||
(or (symbolp o) (byte-optimize--fixnump o)))
|
||||
listval))))))
|
||||
(cons 'memq (cdr form)))
|
||||
(t form)))
|
||||
|
||||
|
|
@ -1622,7 +1617,7 @@ See Info node `(elisp) Integer Basics'."
|
|||
|
||||
;; (list CONSTANTS...) -> '(CONSTANTS...)
|
||||
((and (consp arg) (eq (car arg) 'list)
|
||||
(not (memq nil (mapcar #'macroexp-const-p (cdr arg)))))
|
||||
(all #'macroexp-const-p (cdr arg)))
|
||||
(loop (cons (list 'quote (eval arg)) (cdr args)) newargs))
|
||||
|
||||
(t (loop (cdr args) (cons arg newargs)))))
|
||||
|
|
|
|||
|
|
@ -372,9 +372,7 @@ for the Emacs build itself.")
|
|||
|
||||
;;;###autoload
|
||||
(put 'byte-compile-warnings 'safe-local-variable
|
||||
(lambda (v)
|
||||
(or (symbolp v)
|
||||
(null (delq nil (mapcar (lambda (x) (not (symbolp x))) v))))))
|
||||
(lambda (v) (or (symbolp v) (all #'symbolp v))))
|
||||
|
||||
;;;###autoload
|
||||
(defun byte-compile-warning-enabled-p (warning &optional symbol)
|
||||
|
|
@ -3344,7 +3342,7 @@ lambda-expression."
|
|||
(cons (nth 1 (car body)) (cdr body))
|
||||
(cons tmp body))))
|
||||
(or (eq output-type 'file)
|
||||
(not (delq nil (mapcar 'consp (cdr (car body))))))))
|
||||
(not (any #'consp (cdr (car body)))))))
|
||||
(setq rest (cdr rest)))
|
||||
rest))
|
||||
(let ((byte-compile-vector (byte-compile-constants-vector)))
|
||||
|
|
|
|||
|
|
@ -311,11 +311,11 @@ ENV is a list where each entry takes the shape either:
|
|||
EXTEND is a list of variables which might need to be accessed even from places
|
||||
where they are shadowed, because some part of ENV causes them to be used at
|
||||
places where they originally did not directly appear."
|
||||
(cl-assert (not (delq nil (mapcar (lambda (mapping)
|
||||
(if (eq (cadr mapping) #'apply-partially)
|
||||
(cconv--set-diff (cdr (cddr mapping))
|
||||
extend)))
|
||||
env))))
|
||||
(cl-assert (not (any (lambda (mapping)
|
||||
(and (eq (cadr mapping) #'apply-partially)
|
||||
(cconv--set-diff (cdr (cddr mapping))
|
||||
extend)))
|
||||
env)))
|
||||
|
||||
;; What's the difference between fvrs and envs?
|
||||
;; Suppose that we have the code
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue