[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 087f73c 1/2: Optimize order of iterator-of-directory-files
From: |
Michael Heerdegen |
Subject: |
[elpa] master 087f73c 1/2: Optimize order of iterator-of-directory-files yield elements |
Date: |
Fri, 16 Mar 2018 13:42:48 -0400 (EDT) |
branch: master
commit 087f73c25608268e8ea22e63f705591d3e3fa925
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>
Optimize order of iterator-of-directory-files yield elements
* packages/iterators/iterators.el (iterator-of-directory-files-1):
Yield all non-directory files before descending into subdirectories.
---
packages/iterators/iterators.el | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/packages/iterators/iterators.el b/packages/iterators/iterators.el
index ca3cb03..b333ff8 100644
--- a/packages/iterators/iterators.el
+++ b/packages/iterators/iterators.el
@@ -7,7 +7,7 @@
;; Created: Mar 18 2015
;; Keywords: extensions, elisp
;; Compatibility: GNU Emacs >=25
-;; Version: 0.1
+;; Version: 0.1.1
;; Package-Requires: ((emacs "25"))
@@ -100,19 +100,20 @@ used between the numbers and defaults to 1."
(iter-defun iterator-of-directory-files-1 (directory &optional match nosort
recurse follow-links)
"Helper for `iterator-of-directory-files'."
(when (file-accessible-directory-p directory)
- (let ((files (directory-files directory t match nosort)) file)
- (while (setq file (pop files))
- (cond
- ((not (file-directory-p file))
- (iter-yield file))
- ((member (file-name-nondirectory (directory-file-name file))
- '("." "..")))
- (t
- (iter-yield file)
- (when (and (or follow-links (not (file-symlink-p file)))
- (if (functionp recurse) (funcall recurse file) recurse))
+ (let ((files (directory-files directory t match nosort)) dirs non-dirs)
+ (dolist (file files)
+ (if (file-directory-p file)
+ (push file dirs)
+ (push file non-dirs)))
+ (dolist (file non-dirs)
+ (iter-yield file))
+ (dolist (dir dirs)
+ (unless (member (file-name-nondirectory (directory-file-name dir))
'("." ".."))
+ (iter-yield dir)
+ (when (and (or follow-links (not (file-symlink-p dir)))
+ (if (functionp recurse) (funcall recurse dir) recurse))
(iter-yield-from (iterator-of-directory-files-1
- file match nosort recurse follow-links)))))))))
+ dir match nosort recurse follow-links))))))))
(defun iterator-of-directory-files (directory &optional full match nosort
recurse follow-links)
"Return an iterator of names of files in DIRECTORY.
@@ -126,7 +127,7 @@ directory, and return non-nil when the returned iterator
should
recurse into that directory. Any other non-nil value means
recurse into every readable subdirectory.
-Even with recurse non-nil, don't descent into directories by
+Even with RECURSE non-nil, don't descent into directories by
following symlinks unless FOLLOW-LINKS is non-nil."
(iterator-map
(lambda (file) (if full file (file-relative-name file directory)))