Skip to content

Commit

Permalink
[Fix #8650] Improve hidden files finder performance (#8784)
Browse files Browse the repository at this point in the history
Co-authored-by: Bozhidar Batsov <bozhidar@batsov.com>
  • Loading branch information
tleish and bbatsov committed Sep 25, 2020
1 parent da5b737 commit f788a75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,7 +12,9 @@

### Changes

* [#8785](https://github.com/rubocop-hq/rubocop/pull/8785): Update TargetRubyVersion 2.8 to 3.0 (experimental). ([@em-gazelle][])
* [#8785](https://github.com/rubocop-hq/rubocop/pull/8785): Update TargetRubyVersion 2.8 to 3.0 (experimental). ([@koic][])
* [#8650](https://github.com/rubocop-hq/rubocop/issues/8650): Faster find of hidden files in `TargetFinder` class which improves rubocop initial startup speed. ([@tleish][])

## 0.91.1 (2020-09-23)

Expand Down Expand Up @@ -4916,3 +4918,4 @@
[@fsateler]: https://github.com/fsateler
[@iSarCasm]: https://github.com/iSarCasm
[@em-gazelle]: https://github.com/em-gazelle
[@tleish]: https://github.com/tleish
5 changes: 4 additions & 1 deletion lib/rubocop/target_finder.rb
Expand Up @@ -5,6 +5,8 @@ module RuboCop
# and picking ruby files.
# @api private
class TargetFinder
HIDDEN_PATH_SUBSTRING = "#{File::SEPARATOR}."

def initialize(config_store, options = {})
@config_store = config_store
@options = options
Expand Down Expand Up @@ -55,7 +57,8 @@ def target_files_in_dir(base_dir = Dir.pwd)
# Support Windows: Backslashes from command-line -> forward slashes
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
all_files = find_files(base_dir, File::FNM_DOTMATCH)
hidden_files = Set.new(all_files - find_files(base_dir, 0))
# use file.include? for performance optimization
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }
base_dir_config = @config_store.for(base_dir)

target_files = all_files.select do |file|
Expand Down

0 comments on commit f788a75

Please sign in to comment.