[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#36139: [PATCH] Make better use of the switch op in cond forms
From: |
Stefan Monnier |
Subject: |
bug#36139: [PATCH] Make better use of the switch op in cond forms |
Date: |
Tue, 18 Jun 2019 14:48:44 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> * lisp/emacs-lisp/bytecomp.el (byte-compile-cond-jump-table-info):
> Expand `memq', `memql' and `member' to their corresponding
> equality tests.
> ---
> lisp/emacs-lisp/bytecomp.el | 46 +++++++++++++++++++++++++------------
> 1 file changed, 31 insertions(+), 15 deletions(-)
>
> diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
> index 38cce14fd6..8f089119de 100644
> --- a/lisp/emacs-lisp/bytecomp.el
> +++ b/lisp/emacs-lisp/bytecomp.el
> @@ -4117,23 +4117,39 @@ byte-compile-cond-jump-table-info
> (byte-compile-cond-vars (cadr condition)
> (cl-caddr condition))))
> (obj1 (car-safe vars))
> (obj2 (cdr-safe vars))
> - (body (cdr-safe clause)))
> + (body (cdr-safe clause))
> + equality)
> (unless prev-var
> (setq prev-var obj1))
> - (unless prev-test
> - (setq prev-test test))
> - (if (and obj1 (memq test '(eq eql equal))
> - (eq test prev-test)
> - (eq obj1 prev-var))
> - ;; discard duplicate clauses
> - (unless (assoc obj2 cases test)
> - (push (list obj2 body) cases))
> - (if (and (macroexp-const-p condition) condition)
> - (progn (push (list byte-compile--default-val
> - (or body `(,condition)))
> - cases)
> - (throw 'break t))
> - (setq ok nil)
> + (cond
> + ((and obj1 (memq test '(eq eql equal))
> + (eq obj1 prev-var)
> + (or (not prev-test) (eq test prev-test)))
> + (setq prev-test test)
> + ;; discard duplicate clauses
> + (unless (assoc obj2 cases test)
> + (push (list obj2 body) cases)))
> +
> + ((and obj1 (memq test '(memq memql member))
> + (eq obj1 prev-var)
> + (listp obj2)
> + (setq equality (cdr (assq test '((memq . eq)
> + (memql . eql)
> + (member . equal)))))
> + (or (not prev-test) (eq equality prev-test)))
> + (setq prev-test equality)
> + ;; Expand to individual equality tests.
> + (dolist (elem obj2)
> + (unless (assoc elem cases equality)
> + (push (list elem (or body `(',(funcall test elem
> obj2))))
> + cases))))
> +
> + ((and (macroexp-const-p condition) condition)
> + (push (list byte-compile--default-val
> + (or body `(,condition)))
> + cases)
> + (throw 'break t))
> + (t (setq ok nil)
> (throw 'break nil))))))
> (list (cons prev-test prev-var) (nreverse cases)))))
This patch on its own is problematic because of the code-increase it
can introduce. So I'd suggest merging it with the other one.
Stefan
bug#36139: [PATCH] Make better use of the switch op in cond forms,
Stefan Monnier <=
bug#36139: [PATCH] Make better use of the switch op in cond forms, Stefan Monnier, 2019/06/18
bug#36139: [PATCH] Make better use of the switch op in cond forms, Stefan Monnier, 2019/06/18
bug#36139: [PATCH] Make better use of the switch op in cond forms, Stefan Monnier, 2019/06/18
bug#36139: [PATCH] Make better use of the switch op in cond forms, Stefan Monnier, 2019/06/18