refactor(lib): use with-memoization

Ref: 2b01166d1d
This commit is contained in:
Henrik Lissner 2022-09-06 23:18:49 +02:00
parent cee89a5d3f
commit 3cfcfc5055
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -3,9 +3,7 @@
;;;###autoload
(defun doom-system-distro ()
"Return a symbol representing the installed distro."
;; REVIEW Use `with-memoization' when 27.x support is dropped
(or (get 'doom-system-distro 'cached-value)
(put 'doom-system-distro 'cached-value
(with-memoization (get 'doom-system-distro 'cached-value)
(cond (IS-WINDOWS 'windows)
(IS-MAC 'macos)
((and (file-exists-p "/etc/os-release")
@ -23,7 +21,7 @@
(file-directory-p "/run/current-system"))
(executable-find "guix"))
'guix)
('linux)))))
('linux))))
;;;###autoload
(defun doom-system-distro-version ()
@ -59,9 +57,7 @@
;;;###autoload
(defun doom-system-distro-icon ()
"Display icon for the installed distro."
;; REVIEW Use `with-memoization' when 27.x support is dropped
(or (get 'doom-system-distro-icon 'cached-value)
(put 'doom-system-distro-icon 'cached-value
(with-memoization (get 'doom-system-distro-icon 'cached-value)
(propertize
(pcase (doom-system-distro)
(`windows (all-the-icons-faicon "windows"))
@ -88,14 +84,13 @@
((or `void `artix) "\uF17c")
(_ (all-the-icons-faicon "linux")))
'face '(:height 1)
'display '(raise 0)))))
'display '(raise 0))))
;;;###autoload
(defun doom-system-cpus ()
"Return the max number of processing units on this system.
Tries to be portable. Returns 1 if cannot be determined."
(or (get 'doom-system-cpus 'cached-value)
(put 'doom-system-cpus 'cached-value
(with-memoization (get 'doom-system-cpus 'cached-value)
(let ((cpus
(cond ((fboundp 'w32-get-nproc)
(w32-get-nproc))
@ -118,4 +113,4 @@ Tries to be portable. Returns 1 if cannot be determined."
(string-to-number (cdr cpus))
(user-error "Failed to look up number of processors, because:\n\n%s"
(cdr cpus)))))
1))))))
1)))))