Byte-compile mode-line segment :eval forms

Byte-compiled function calls are ~10% faster than evalling quoted forms.
This commit is contained in:
Henrik Lissner 2018-07-29 19:14:50 +02:00
parent 1205db0f73
commit 55870458e6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -23,14 +23,15 @@ keep them left and right aligned respectively."
body) body)
(macroexp-progn (macroexp-progn
(if (not (keywordp (car rest))) (if (not (keywordp (car rest)))
`((defvar-local ,name nil ,docstring) (append `((defvar-local ,name nil ,docstring)
(setq-default (put ',name 'risky-local-variable t))
,name (if (or (stringp (car rest))
,(if (or (stringp (car rest)) (memq (car (car-safe rest)) '(:eval :propertize)))
(memq (car (car-safe rest)) '(:eval :propertize))) `((setq-default ,name ,(car rest)))
(car rest) (let ((fn (intern (format "+modeline--%s" name))))
`(quote (:eval ,(macroexp-progn rest))))) `((fset ',fn (lambda () ,@rest))
(put ',name 'risky-local-variable t)) (byte-compile ',fn)
(setq-default ,name (quote (:eval (,fn))))))))
;; isolate body ;; isolate body
(setq body rest) (setq body rest)
(while (keywordp (car body)) (while (keywordp (car body))