Skip to content

Commit

Permalink
Dir.children is available since Feature #11302. FileUtils uses
Browse files Browse the repository at this point in the history
Dir.each on an internal method encapsulated on a private class
`Entry_#entry`, having no '.' neither '..' entries would make
now superfluous a chained reject filtering.

This change can improve the performance of these FileUtils
methods when the provided path covers thousands of files or
directories:

- chmod_R
- chown_R
- remove_entry
- remove_entry_secure
- rm_r
- remove_dir
- copy_entry

Related: Feature #13896 https://bugs.ruby-lang.org/issues/13896

[Feature #14109][Fix GH-1754]

Co-Authored-By: esparta <[email protected]>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
hsbt committed Nov 28, 2018
1 parent d911f14 commit d8c665c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,7 @@ def door?
def entries
opts = {}
opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
Dir.entries(path(), opts)\
.reject {|n| n == '.' or n == '..' }\
Dir.children(path, opts)\
.map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
end

Expand Down

1 comment on commit d8c665c

@esparta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build is broken because Dir.children only exist on ruby >= 2.5, and the gem is still supporting 2.3 and 2.4 series.
Should this commit wait until 2.5 being the minimal? Also, what about jruby (not implemented yet)?

Please sign in to comment.