Refactor out map.el usage

After some profiling, it turns out map-put and map-delete are 5-7x
slower (more on Emacs 25) than delq, setf/alist-get and add-to-list for
small lists (under 250 items), which is exactly how I've been using
them.

The only caveat is alist-get's signature is different on Emacs 25, thus
a polyfill is necessary in core-lib.
This commit is contained in:
Henrik Lissner 2018-06-23 16:48:58 +02:00
parent f602a1f607
commit f6dc6ac74e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
29 changed files with 177 additions and 146 deletions

View file

@ -3,7 +3,6 @@
;; Built in packages we use a lot of
(require 'subr-x)
(require 'cl-lib)
(require 'map)
(eval-and-compile
(unless EMACS26+
@ -11,7 +10,23 @@
;; if-let and when-let are deprecated in Emacs 26+ in favor of their
;; if-let* variants, so we alias them for 25 users.
(defalias 'if-let* #'if-let)
(defalias 'when-let* #'when-let))))
(defalias 'when-let* #'when-let)
;; `alist-get' doesn't have its 5th argument before Emacs 26
(defun doom*alist-get (key alist &optional default remove testfn)
"Return the value associated with KEY in ALIST.
If KEY is not found in ALIST, return DEFAULT.
Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'.
This is a generalized variable suitable for use with `setf'.
When using it to set a value, optional argument REMOVE non-nil
means to remove KEY from ALIST if the new value is `eql' to DEFAULT."
(ignore remove) ;;Silence byte-compiler.
(let ((x (if (not testfn)
(assq key alist)
(assoc key alist testfn))))
(if x (cdr x) default)))
(advice-add #'alist-get :override #'doom*alist-get))))
;;
@ -402,7 +417,7 @@ The available conditions are:
collect `(add-hook ',hook #',hook-name))
`((add-hook 'after-change-major-mode-hook #',hook-name))))))
(match
`(map-put doom-auto-minor-mode-alist ,match ',mode))
`(add-to-list 'doom-auto-minor-mode-alist '(,match . ,mode)))
((user-error "Invalid `associate!' rules for mode [%s] (:modes %s :match %s :files %s :when %s)"
mode modes match files when)))))