From c9e3deffab6e9de3a214a3b7f7a5921018fc1a9d Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Wed, 10 Dec 2014 05:38:23 +0100 Subject: [PATCH] Speed up directory-files-recursively * files.el (directory-files-recursively): Use `file-name-all-completions' instead of `directory-files' for greater speed. --- lisp/ChangeLog | 4 ++++ lisp/files.el | 27 +++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 20461a654fe..445a4618714 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,9 @@ 2014-12-10 Lars Magne Ingebrigtsen + * files.el (directory-files-recursively): Use + `file-name-all-completions' instead of `directory-files' for + greater speed. + * net/shr.el (shr-tag-object): Don't bug out on text elements in . diff --git a/lisp/files.el b/lisp/files.el index 5127519732d..e948c745b3c 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -769,18 +769,21 @@ and alphabetical order. If INCLUDE-DIRECTORIES, also include directories that have matching names." (let ((result nil) (files nil)) - (dolist (file (directory-files dir t)) - (let ((leaf (file-name-nondirectory file))) - (unless (member leaf '("." "..")) - (if (file-directory-p file) - (progn - (when (and include-directories - (string-match match leaf)) - (push file files)) - (setq result (nconc result (directory-files-recursively - file match include-directories)))) - (when (string-match match leaf) - (push file files)))))) + (dolist (file (sort (file-name-all-completions "" dir) + 'string<)) + (unless (member file '("./" "../")) + (if (= (aref file (1- (length file))) ?/) + (progn + (setq result (nconc result (directory-files-recursively + (expand-file-name file dir) + match include-directories))) + (when (and include-directories + (string-match match + (substring file 0 (1- (length file))))) + (setq result (nconc result (list + (expand-file-name file dir)))))) + (when (string-match match file) + (push (expand-file-name file dir) files))))) (nconc result (nreverse files)))) (defun load-file (file) -- 2.39.2