aboutsummaryrefslogtreecommitdiff
path: root/projectile.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2026-02-28 08:41:09 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2026-02-28 08:54:10 +0200
commitb5936d67c70f5d18094d31eb488304a9a0be8d16 (patch)
treea4239766f2b61a8f0058e5d18e523bdab3d6c5c9 /projectile.el
parente3e67f8740a86f8053e687ee28091555d7aad35a (diff)
Pre-compute timestamps in sort-by-modification/access-time
The sort comparator was calling file-attributes on every comparison, resulting in O(n log n) stat calls. Pre-compute all timestamps into a hash table first (O(n) stats), then sort using cached values. Also use file-attribute-modification-time/file-attribute-access-time accessors instead of raw nth.
Diffstat (limited to 'projectile.el')
-rw-r--r--projectile.el20
1 files changed, 12 insertions, 8 deletions
diff --git a/projectile.el b/projectile.el
index f880e71..d35df00 100644
--- a/projectile.el
+++ b/projectile.el
@@ -2688,20 +2688,24 @@ Parameters MODE VARIABLE VALUE are passed directly to
(defun projectile-sort-by-modification-time (files)
"Sort FILES by modification time."
- (let ((default-directory (projectile-project-root)))
+ (let ((default-directory (projectile-project-root))
+ (mtimes (make-hash-table :test 'equal :size (length files))))
+ (dolist (file files)
+ (puthash file (file-attribute-modification-time (file-attributes file)) mtimes))
(seq-sort (lambda (file1 file2)
- (let ((file1-mtime (nth 5 (file-attributes file1)))
- (file2-mtime (nth 5 (file-attributes file2))))
- (not (time-less-p file1-mtime file2-mtime))))
+ (not (time-less-p (gethash file1 mtimes)
+ (gethash file2 mtimes))))
files)))
(defun projectile-sort-by-access-time (files)
"Sort FILES by access time."
- (let ((default-directory (projectile-project-root)))
+ (let ((default-directory (projectile-project-root))
+ (atimes (make-hash-table :test 'equal :size (length files))))
+ (dolist (file files)
+ (puthash file (file-attribute-access-time (file-attributes file)) atimes))
(seq-sort (lambda (file1 file2)
- (let ((file1-atime (nth 4 (file-attributes file1)))
- (file2-atime (nth 4 (file-attributes file2))))
- (not (time-less-p file1-atime file2-atime))))
+ (not (time-less-p (gethash file1 atimes)
+ (gethash file2 atimes))))
files)))