emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 96ec034: Speed up ls-lisp


From: Eli Zaretskii
Subject: master 96ec034: Speed up ls-lisp
Date: Sat, 31 Oct 2020 05:43:18 -0400 (EDT)

branch: master
commit 96ec0340716292f577f6dcaa0f8102f1a04e1d5e
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    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)
---
 lisp/ls-lisp.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 8851522..e264620 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -836,6 +836,9 @@ Return nil if no time switch found."
        ((memq ?t switches) 5)          ; last modtime
        ((memq ?u switches) 4)))        ; last access
 
+(defvar ls-lisp--time-locale nil
+  "Locale to be used for formatting file times.")
+
 (defun ls-lisp-format-time (file-attr time-index)
   "Format time for file with attributes FILE-ATTR according to TIME-INDEX.
 Use 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."
     (condition-case nil
        ;; Use traditional time format in the C or POSIX locale,
        ;; ISO-style time format otherwise, so columns line up.
-       (let ((locale system-time-locale))
+       (let ((locale (or system-time-locale ls-lisp--time-locale)))
          (if (not locale)
              (let ((vars '("LC_ALL" "LC_TIME" "LANG")))
                (while (and vars (not (setq locale (getenv (car vars)))))
-                 (setq vars (cdr vars)))))
+                 (setq vars (cdr vars)))
+                ;; Cache the locale for next calls.
+                (setq ls-lisp--time-locale (or locale "C"))))
          (if (member locale '("C" "POSIX"))
              (setq locale nil))
          (format-time-string



reply via email to

[Prev in Thread] Current Thread [Next in Thread]