1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Find.find -> Use Dir.children instead of Dir.entries

Dir.children is available since Feature #11302.
Find.find can use of the new list (having no '.' neither '..' entries),
making now superflous an if statement.

This change can improve the performance of Find.find when the path
has lots of entries (thousands?).

https://bugs.ruby-lang.org/issues/11302
patched by Espartaco Palma <esparta@gmail.com>
https://github.com/ruby/ruby/pull/1697 fix GH-1697
[Feature #13896]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2017-09-15 17:00:49 +00:00
parent 40f3c519d5
commit b2996b30d9

View file

@ -55,14 +55,13 @@ module Find
end end
if s.directory? then if s.directory? then
begin begin
fs = Dir.entries(file, encoding: enc) fs = Dir.children(file, encoding: enc)
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
raise unless ignore_error raise unless ignore_error
next next
end end
fs.sort! fs.sort!
fs.reverse_each {|f| fs.reverse_each {|f|
next if f == "." or f == ".."
f = File.join(file, f) f = File.join(file, f)
ps.unshift f.untaint ps.unshift f.untaint
} }