[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master df3ece9: Optimise assoc and rassoc with symbol key to assq and ra
From: |
Mattias Engdeg�rd |
Subject: |
master df3ece9: Optimise assoc and rassoc with symbol key to assq and rassq |
Date: |
Tue, 7 Jul 2020 12:17:24 -0400 (EDT) |
branch: master
commit df3ece9d2ed61c9526dbf718e3c96d72bd53dccb
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
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.
---
lisp/emacs-lisp/byte-opt.el | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 646994a..194ceee 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -842,6 +842,15 @@
;; Arity errors reported elsewhere.
form))
+(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))
+ 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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master df3ece9: Optimise assoc and rassoc with symbol key to assq and rassq,
Mattias Engdeg�rd <=