diff options
author | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2014-12-10 05:38:23 +0100 |
---|---|---|
committer | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2014-12-10 05:38:23 +0100 |
commit | c9e3deffab6e9de3a214a3b7f7a5921018fc1a9d (patch) | |
tree | 795acf853f30d92f1e028327bec91b14f2e4f039 | |
parent | ef8892db3cdf679231cf71613f14589fc3702a80 (diff) | |
download | emacs-c9e3deffab6e9de3a214a3b7f7a5921018fc1a9d.tar.gz |
Speed up directory-files-recursively
* files.el (directory-files-recursively): Use
`file-name-all-completions' instead of `directory-files' for
greater speed.
-rw-r--r-- | lisp/ChangeLog | 4 | ||||
-rw-r--r-- | 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 <larsi@gnus.org> + * 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 <object>. 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) |