Skip to content

Commit 2b95956

Browse files
use _readdirx for walkdir (#53545)
On a M2 Mac there is some benefit, but assumed to be much greater on slower filesystems. ``` # master julia> @Btime collect(walkdir(expanduser("~/Downloads"))); 380.086 ms (310696 allocations: 25.29 MiB) # This PR julia> @Btime collect(walkdir(expanduser("~/Downloads"))); 289.747 ms (103300 allocations: 7.50 MiB) ``` The implementations appear to produce the same result ``` julia> collect(walkdir(expanduser("~/Downloads"))) == collect(walkdirx(expanduser("~/Downloads"))) true ```
1 parent 188e386 commit 2b95956

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

base/file.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,18 +1089,16 @@ function walkdir(root; topdown=true, follow_symlinks=false, onerror=throw)
10891089
end
10901090
return
10911091
end
1092-
content = tryf(readdir, root)
1093-
content === nothing && return
1094-
dirs = Vector{eltype(content)}()
1095-
files = Vector{eltype(content)}()
1096-
for name in content
1097-
path = joinpath(root, name)
1098-
1092+
entries = tryf(_readdirx, root)
1093+
entries === nothing && return
1094+
dirs = Vector{String}()
1095+
files = Vector{String}()
1096+
for entry in entries
10991097
# If we're not following symlinks, then treat all symlinks as files
1100-
if (!follow_symlinks && something(tryf(islink, path), true)) || !something(tryf(isdir, path), false)
1101-
push!(files, name)
1098+
if (!follow_symlinks && something(tryf(islink, entry), true)) || !something(tryf(isdir, entry), false)
1099+
push!(files, entry.name)
11021100
else
1103-
push!(dirs, name)
1101+
push!(dirs, entry.name)
11041102
end
11051103
end
11061104

0 commit comments

Comments
 (0)