From 822226cae207ee94825cbac2434039f3857c5b65 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Sat, 4 Sep 2010 02:16:01 +0200 Subject: [PATCH] Only recurse down into subdirectories if the link count is more than 2. This results in a 100x speed up on my nnmh spool, and that's from an SSD disk, and not over nfs. --- lisp/ChangeLog | 4 ++++ lisp/nnmh.el | 35 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 94fb6805a..1ae82d2fe 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2010-09-04 Lars Magne Ingebrigtsen + + * nnmh.el (nnmh-request-list-1): Optimize for speed. + 2010-09-03 Lars Magne Ingebrigtsen * mm-util.el (mm-image-load-path): Just return the image directories, diff --git a/lisp/nnmh.el b/lisp/nnmh.el index 05eb669fa..86f751c76 100644 --- a/lisp/nnmh.el +++ b/lisp/nnmh.el @@ -207,21 +207,29 @@ as unread by Gnus.") (defun nnmh-request-list-1 (dir) (setq dir (expand-file-name dir)) ;; Recurse down all directories. - (let ((dirs (and (file-readable-p dir) - (nnheader-directory-files dir t nil t))) - rdir) + (let ((files (nnheader-directory-files dir t nil t)) + (max 0) + min rdir attributes num) ;; Recurse down directories. - (while (setq rdir (pop dirs)) - (when (and (file-directory-p rdir) + (dolist (rdir files) + (setq attributes (file-attributes rdir)) + (when (null (nth 0 attributes)) + (setq file (file-name-nondirectory rdir)) + (when (string-match "^[0-9]+$" file) + (setq num (string-to-number file)) + (setq max (max max num)) + (when (or (null min) + (< num min)) + (setq min num)))) + (when (and (eq (nth 0 attributes) t) ; Is a directory + (> (nth 1 attributes) 2) ; Has sub-directories (file-readable-p rdir) (not (equal (file-truename rdir) (file-truename dir)))) - (nnmh-request-list-1 rdir)))) - ;; For each directory, generate an active file line. - (unless (string= (expand-file-name nnmh-toplev) dir) - (let ((files (mapcar 'string-to-number - (directory-files dir nil "^[0-9]+$" t)))) - (when files + (nnmh-request-list-1 rdir))) + ;; For each directory, generate an active file line. + (unless (string= (expand-file-name nnmh-toplev) dir) + (when min (with-current-buffer nntp-server-buffer (goto-char (point-max)) (insert @@ -233,14 +241,13 @@ as unread by Gnus.") (file-truename (file-name-as-directory (expand-file-name nnmh-toplev)))) dir) - (mm-string-to-multibyte ;Why? Isn't it multibyte already? + (mm-string-to-multibyte ;Why? Isn't it multibyte already? (mm-encode-coding-string (nnheader-replace-chars-in-string (substring dir (match-end 0)) ?/ ?.) nnmail-pathname-coding-system))) - (apply 'max files) - (apply 'min files))))))) + max min)))))) t) (deffoo nnmh-request-newgroups (date &optional server) -- 2.25.1