aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2020-10-31 11:41:53 +0200
committerEli Zaretskii2020-10-31 11:41:53 +0200
commit96ec0340716292f577f6dcaa0f8102f1a04e1d5e (patch)
tree30e7f40fc143741f2ab0d02d3a24806a6718113f
parent41c4f337c8f798d4700dcd13b73ad4ccdb3257eb (diff)
downloademacs-96ec0340716292f577f6dcaa0f8102f1a04e1d5e.tar.gz
emacs-96ec0340716292f577f6dcaa0f8102f1a04e1d5e.zip
Speed up ls-lisp
This speeds up Dired by 25% in large directories. * lisp/ls-lisp.el (ls-lisp--time-locale): New defvar. (ls-lisp-format-time): calculate the locale for formatting times only once and cache the value in 'ls-lisp--time-locale'. (Bug#44273)
-rw-r--r--lisp/ls-lisp.el9
1 files changed, 7 insertions, 2 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 8851522bbdb..e2646209313 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -836,6 +836,9 @@ Return nil if no time switch found."
836 ((memq ?t switches) 5) ; last modtime 836 ((memq ?t switches) 5) ; last modtime
837 ((memq ?u switches) 4))) ; last access 837 ((memq ?u switches) 4))) ; last access
838 838
839(defvar ls-lisp--time-locale nil
840 "Locale to be used for formatting file times.")
841
839(defun ls-lisp-format-time (file-attr time-index) 842(defun ls-lisp-format-time (file-attr time-index)
840 "Format time for file with attributes FILE-ATTR according to TIME-INDEX. 843 "Format time for file with attributes FILE-ATTR according to TIME-INDEX.
841Use the same method as ls to decide whether to show time-of-day or year, 844Use the same method as ls to decide whether to show time-of-day or year,
@@ -851,11 +854,13 @@ All ls time options, namely c, t and u, are handled."
851 (condition-case nil 854 (condition-case nil
852 ;; Use traditional time format in the C or POSIX locale, 855 ;; Use traditional time format in the C or POSIX locale,
853 ;; ISO-style time format otherwise, so columns line up. 856 ;; ISO-style time format otherwise, so columns line up.
854 (let ((locale system-time-locale)) 857 (let ((locale (or system-time-locale ls-lisp--time-locale)))
855 (if (not locale) 858 (if (not locale)
856 (let ((vars '("LC_ALL" "LC_TIME" "LANG"))) 859 (let ((vars '("LC_ALL" "LC_TIME" "LANG")))
857 (while (and vars (not (setq locale (getenv (car vars))))) 860 (while (and vars (not (setq locale (getenv (car vars)))))
858 (setq vars (cdr vars))))) 861 (setq vars (cdr vars)))
862 ;; Cache the locale for next calls.
863 (setq ls-lisp--time-locale (or locale "C"))))
859 (if (member locale '("C" "POSIX")) 864 (if (member locale '("C" "POSIX"))
860 (setq locale nil)) 865 (setq locale nil))
861 (format-time-string 866 (format-time-string