From f788a75e52873f3c61459f427c4026cddeb1ed11 Mon Sep 17 00:00:00 2001 From: tleish Date: Fri, 25 Sep 2020 00:37:46 -0600 Subject: [PATCH] [Fix #8650] Improve hidden files finder performance (#8784) Co-authored-by: Bozhidar Batsov --- CHANGELOG.md | 3 +++ lib/rubocop/target_finder.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 125122ef8f9..0f04e919371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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 diff --git a/lib/rubocop/target_finder.rb b/lib/rubocop/target_finder.rb index 3f6f45ed397..76294783611 100644 --- a/lib/rubocop/target_finder.rb +++ b/lib/rubocop/target_finder.rb @@ -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 @@ -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|