GNU bug report logs -
#36139
[PATCH] Make better use of the switch op in cond forms
Previous Next
Reported by: Mattias Engdegård <mattiase <at> acm.org>
Date: Sat, 8 Jun 2019 15:16:02 UTC
Severity: wishlist
Tags: patch
Done: Mattias Engdegård <mattiase <at> acm.org>
Bug is archived. No further changes may be made.
Full log
Message #32 received at 36139 <at> debbugs.gnu.org (full text, mbox):
> * lisp/emacs-lisp/pcase.el (pcase--u1):
> Use the most specific of `memq', `memql' and `member' in or-patterns
> with constant cases. This improves performance and may help the byte-code
> compiler generate a switch.
> * test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-member):
> Add mixed-type or-pattern test cases.
> ---
> lisp/emacs-lisp/pcase.el | 15 ++++++++-------
> test/lisp/emacs-lisp/pcase-tests.el | 6 ++++--
> 2 files changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
> index a644453a94..ae2cf8eb02 100644
> --- a/lisp/emacs-lisp/pcase.el
> +++ b/lisp/emacs-lisp/pcase.el
> @@ -785,25 +785,26 @@ pcase--u1
> ((eq 'or (caar matches))
> (let* ((alts (cdar matches))
> (var (if (eq (caar alts) 'match) (cadr (car alts))))
> - (simples '()) (others '()) (memql-ok t))
> + (simples '()) (others '()) (mem-fun 'memq))
> (when var
> (dolist (alt alts)
> (if (and (eq (car alt) 'match) (eq var (cadr alt))
> (let ((upat (cddr alt)))
> (eq (car-safe upat) 'quote)))
> (let ((val (cadr (cddr alt))))
> - (unless (or (integerp val) (symbolp val))
> - (setq memql-ok nil))
> - (push (cadr (cddr alt)) simples))
> + (cond ((integerp val)
> + (when (eq mem-fun 'memq)
> + (setq mem-fun 'memql)))
> + ((not (symbolp val))
> + (setq mem-fun 'member)))
> + (push val simples))
> (push alt others))))
> (cond
> ((null alts) (error "Please avoid it") (pcase--u rest))
> ;; Yes, we can use `memql' (or `member')!
> ((> (length simples) 1)
> (pcase--u1 (cons `(match ,var
> - . (pred (pcase--flip
> - ,(if memql-ok #'memql #'member)
> - ',simples)))
> + . (pred (pcase--flip ,mem-fun ',simples)))
> (cdr matches))
> code vars
> (if (null others) rest
LGTM. The other direction is to just always use `member`
and speed up the implementation of `member` by testing the type of
the first arg and dispatch to memq/memql when possible.
Stefan
This bug report was last modified 5 years and 323 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.