Commit df3ece9d authored by Mattias Engdegård's avatar Mattias Engdegård

Optimise assoc and rassoc with symbol key to assq and rassq

This is the same transformation made for member to memq.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-assoc): New function.
(assoc, rassoc): Set the byte-optimizer property.
parent 1a850f4b
Pipeline #6001 failed with stage
in 31 seconds
......@@ -842,6 +842,15 @@
;; Arity errors reported elsewhere.
(defun byte-optimize-assoc (form)
;; Replace 2-argument `assoc' with `assq', `rassoc' with `rassq',
;; if the first arg is a symbol.
(if (and (= (length form) 3)
(byte-optimize--constant-symbol-p (nth 1 form)))
(cons (if (eq (car form) 'assoc) 'assq 'rassq)
(cdr form))
(defun byte-optimize-memq (form)
;; (memq foo '(bar)) => (and (eq foo 'bar) '(bar))
(if (= (length (cdr form)) 2)
......@@ -886,6 +895,8 @@
(put 'memq 'byte-optimizer 'byte-optimize-memq)
(put 'memql 'byte-optimizer 'byte-optimize-member)
(put 'member 'byte-optimizer 'byte-optimize-member)
(put 'assoc 'byte-optimizer 'byte-optimize-assoc)
(put 'rassoc 'byte-optimizer 'byte-optimize-assoc)
(put '+ 'byte-optimizer 'byte-optimize-plus)
(put '* 'byte-optimizer 'byte-optimize-multiply)
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