]> git.eshelyaron.com Git - emacs.git/commitdiff
Speed up directory-files-recursively
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 10 Dec 2014 04:38:23 +0000 (05:38 +0100)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 10 Dec 2014 04:38:23 +0000 (05:38 +0100)
* files.el (directory-files-recursively): Use
`file-name-all-completions' instead of `directory-files' for
greater speed.

lisp/ChangeLog
lisp/files.el

index 20461a654fea73edbc34f1476dbccb1bd8da9a22..445a461871440c13aa045e1e23cce3e3a67b2e21 100644 (file)
@@ -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>.
 
index 5127519732d751d228fa9bdcd97466be5e48a0e8..e948c745b3cfed08dbf526985b9ee98644fd3ff6 100644 (file)
@@ -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)