perf(lib): memoize doom-system-* functions

This commit is contained in:
Henrik Lissner 2022-08-12 20:24:17 +02:00
parent 3239ab8b2e
commit c540f1b515
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -3,23 +3,26 @@
;;;###autoload
(defun doom-system-distro ()
"Return a symbol representing the installed distro."
(cond (IS-WINDOWS 'windows)
(IS-MAC 'macos)
((and (file-exists-p "/etc/os-release")
(with-temp-buffer
(insert-file-contents "/etc/os-release")
(when (re-search-forward "^ID=\"?\\([^\"\n]+\\)\"?" nil t)
(intern (downcase (match-string 1)))))))
;; A few redundancies in case os-release fails us
((file-exists-p "/etc/debian_version")
'debian)
((executable-find "nixos-version")
'nixos)
((and (or (file-exists-p "/etc/config.scm")
(file-directory-p "/run/current-system"))
(executable-find "guix"))
'guix)
('linux)))
;; REVIEW Use `with-memoization' when 27.x support is dropped
(or (get 'doom-system-distro 'cached-value)
(put 'doom-system-distro 'cached-value
(cond ((featurep :os 'windows) 'windows)
((featurep :os 'macos) 'macos)
((and (file-exists-p "/etc/os-release")
(with-temp-buffer
(insert-file-contents "/etc/os-release")
(when (re-search-forward "^ID=\"?\\([^\"\n]+\\)\"?" nil t)
(intern (downcase (match-string 1)))))))
;; A few redundancies in case os-release fails us
((file-exists-p "/etc/debian_version")
'debian)
((executable-find "nixos-version")
'nixos)
((and (or (file-exists-p "/etc/config.scm")
(file-directory-p "/run/current-system"))
(executable-find "guix"))
'guix)
('linux)))))
;;;###autoload
(defun doom-system-distro-version ()
@ -49,33 +52,36 @@
;;;###autoload
(defun doom-system-distro-icon ()
"Display icon for the installed distro."
(propertize
(pcase (doom-system-distro)
(`windows (all-the-icons-faicon "windows"))
(`macos (all-the-icons-faicon "apple"))
(`arch "\uF303")
(`debian "\uF306")
(`raspbian "\uF315")
(`ubuntu "\uF31b")
(`elementary "\uF309")
(`fedora "\uF30a")
(`coreos "\uF305")
(`gentoo "\uF30d")
(`mageia "\uF310")
(`centos "\uF304")
((or `opensuse `tumbleweed) "\uF314")
(`sabayon "\uF317")
(`slackware "\uF319")
(`linuxmint "\uF30e")
(`alpine "\uF300")
(`aosc "\uF301")
(`nixos "\uF313")
(`devuan "\uF307")
(`manjaro "\uF312")
((or `void `artix) "\uF17c")
(_ (all-the-icons-faicon "linux")))
'face '(:height 1)
'display '(raise 0)))
;; 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
(propertize
(pcase (doom-system-distro)
(`windows (all-the-icons-faicon "windows"))
(`macos (all-the-icons-faicon "apple"))
(`arch "\uF303")
(`debian "\uF306")
(`raspbian "\uF315")
(`ubuntu "\uF31b")
(`elementary "\uF309")
(`fedora "\uF30a")
(`coreos "\uF305")
(`gentoo "\uF30d")
(`mageia "\uF310")
(`centos "\uF304")
((or `opensuse `tumbleweed) "\uF314")
(`sabayon "\uF317")
(`slackware "\uF319")
(`linuxmint "\uF30e")
(`alpine "\uF300")
(`aosc "\uF301")
(`nixos "\uF313")
(`devuan "\uF307")
(`manjaro "\uF312")
((or `void `artix) "\uF17c")
(_ (all-the-icons-faicon "linux")))
'face '(:height 1)
'display '(raise 0)))))
;;;###autoload
(defun doom-system-cpus ()