refactor(lib): use num-processors

This C function was introduced in Emacs 28.1.
This commit is contained in:
Henrik Lissner 2022-09-08 13:35:14 +02:00
parent cd269753cf
commit 6e8de0bd89
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -83,29 +83,31 @@
"Return the max number of processing units on this system. "Return the max number of processing units on this system.
Tries to be portable. Returns 1 if cannot be determined." Tries to be portable. Returns 1 if cannot be determined."
(with-memoization (get 'doom-system-cpus 'cached-value) (with-memoization (get 'doom-system-cpus 'cached-value)
(let ((cpus (if (fboundp 'num-processors)
(cond ((fboundp 'w32-get-nproc) (num-processors) ; added in Emacs 28.1
(w32-get-nproc)) (let ((cpus
((getenv "NUMBER_OF_PROCESSORS")) (cond ((fboundp 'w32-get-nproc)
((executable-find "nproc") (w32-get-nproc))
(doom-call-process "nproc")) ((getenv "NUMBER_OF_PROCESSORS"))
((executable-find "sysctl") ((executable-find "nproc")
(doom-call-process "sysctl" "-n" "hw.ncpu"))))) (doom-call-process "nproc"))
(max ((executable-find "sysctl")
1 (or (cl-typecase cpus (doom-call-process "sysctl" "-n" "hw.ncpu")))))
(integer cpus) (max
(string 1 (or (cl-typecase cpus
(condition-case _ (integer cpus)
(string-to-number cpus) (string
(wrong-type-argument (condition-case _
(user-error "NUMBER_OF_PROCESSORS contains an invalid value: %S" (string-to-number cpus)
cpus)))) (wrong-type-argument
(cons (user-error "NUMBER_OF_PROCESSORS contains an invalid value: %S"
(if (zerop (car cpus)) cpus))))
(string-to-number (cdr cpus)) (cons
(user-error "Failed to look up number of processors, because:\n\n%s" (if (zerop (car cpus))
(cdr cpus))))) (string-to-number (cdr cpus))
1))))) (user-error "Failed to look up number of processors, because:\n\n%s"
(cdr cpus)))))
1))))))
(provide 'doom-lib '(system)) (provide 'doom-lib '(system))
;;; system.el ends here ;;; system.el ends here