Optimize featurep! macro

If we can use doom--current-module and evaluate membership at
compile-time, we same a little time, but a fair bit more if
we byte-compile.
This commit is contained in:
Henrik Lissner 2018-06-27 23:17:17 +02:00
parent f6478ab068
commit 0f0f5f6584
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -367,16 +367,17 @@ Module FLAGs are set in your config's `doom!' block, typically in
When this macro is used from inside a module, MODULE and SUBMODULE can be When this macro is used from inside a module, MODULE and SUBMODULE can be
omitted. eg. (featurep! +flag1)" omitted. eg. (featurep! +flag1)"
(unless submodule (unless submodule
(let* ((path (FILE!)) (let ((module-pair
(module-pair (doom-module-from-path path))) (or doom--current-module
(doom-module-from-path (FILE!)))))
(unless module-pair (unless module-pair
(error "featurep! couldn't detect what module its in! (in %s)" path)) (error "featurep! couldn't detect what module its in! (in %s)" path))
(setq flag module (setq flag module
module (car module-pair) module (car module-pair)
submodule (cdr module-pair)))) submodule (cdr module-pair))))
(if flag (if flag
`(and (memq ',flag (doom-module-get ,module ',submodule :flags)) t) (and (memq flag (doom-module-get module submodule :flags)) t)
`(doom-module-p ,module ',submodule))) (doom-module-p module submodule)))
;; ;;