perf(scanner): linear expand-scan-path traversal
ober
097422944252ba9861546d48a29416e784871019
--- a/gitsafe/scanner.ss +++ b/gitsafe/scanner.ss @@ -910,27 +910,26 @@ (def (expand-scan-path path) (let ([visited (make-hash-table)]) - (let expand ([path path]) + (let expand ([path path] [acc '()]) (cond - [(not (file-exists? path)) '()] + [(not (file-exists? path)) acc] [(and (file-directory? path) (string=? (path-strip-directory path) ".git")) - '()] + acc] [(file-directory? path) (let ([id (directory-identity path)]) (if (and id (hash-key? visited id)) - '() + acc (begin (when id (hash-put! visited id #t)) - (let loop ([entries (try (directory-list path) (catch (e) '()))] - [acc '()]) + (let loop ([entries (reverse (try (directory-list path) (catch (e) '())))] + [acc acc]) (if (null? entries) - (reverse acc) + acc (let* ([name (entry->string (car entries))] [full (join-path path name)]) - (loop (cdr entries) - (append (expand full) acc))))))))] - [else (list path)])))) + (loop (cdr entries) (expand full acc))))))))] + [else (cons path acc)])))) (def (expand-scan-paths paths) (apply append (map expand-scan-path paths)))