Skip to content

Commit

Permalink
Merge pull request #10953 from ydah/speed_improvement
Browse files Browse the repository at this point in the history
[Fix #10919] Fix a huge performance regression between 1.32.0 and 1.33.0
  • Loading branch information
koic committed Aug 26, 2022
2 parents 2daf9f1 + 8ebe36c commit 54027a3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog/fix_fix_a_huge_performance_regression.md
@@ -0,0 +1 @@
* [#10919](https://github.com/rubocop/rubocop/issues/10919): Fix a huge performance regression between 1.32.0 and 1.33.0. ([@ydah][])
15 changes: 10 additions & 5 deletions lib/rubocop/cop/mixin/allowed_methods.rb
Expand Up @@ -17,16 +17,21 @@ def allowed_method?(name)

# @api public
def allowed_methods
deprecated_values = cop_config_deprecated_values
if deprecated_values.any?(Regexp)
cop_config.fetch('AllowedMethods', [])
if cop_config_deprecated_values.any?(Regexp)
cop_config_allowed_methods
else
Array(cop_config['AllowedMethods']).concat(deprecated_values)
cop_config_allowed_methods + cop_config_deprecated_values
end
end

def cop_config_allowed_methods
@cop_config_allowed_methods ||= Array(cop_config.fetch('AllowedMethods', []))
end

def cop_config_deprecated_values
Array(cop_config['IgnoredMethods']).concat(Array(cop_config['ExcludedMethods']))
@cop_config_deprecated_values ||=
Array(cop_config.fetch('IgnoredMethods', [])) +
Array(cop_config.fetch('ExcludedMethods', []))
end
end
# @deprecated IgnoredMethods class has been replaced with AllowedMethods.
Expand Down
18 changes: 13 additions & 5 deletions lib/rubocop/cop/mixin/allowed_pattern.rb
Expand Up @@ -30,15 +30,23 @@ def matches_allowed_pattern?(line)
def allowed_patterns
# Since there could be a pattern specified in the default config, merge the two
# arrays together.
patterns = Array(cop_config['AllowedPatterns']).concat(Array(cop_config['IgnoredPatterns']))
deprecated_values = cop_config_deprecated_methods_values
return patterns unless deprecated_values.any?(Regexp)
if cop_config_deprecated_methods_values.any?(Regexp)
cop_config_patterns_values + cop_config_deprecated_methods_values
else
cop_config_patterns_values
end
end

Array(patterns.concat(deprecated_values))
def cop_config_patterns_values
@cop_config_patterns_values ||=
Array(cop_config.fetch('AllowedPatterns', [])) +
Array(cop_config.fetch('IgnoredPatterns', []))
end

def cop_config_deprecated_methods_values
Array(cop_config['IgnoredMethods']).concat(Array(cop_config['ExcludedMethods']))
@cop_config_deprecated_methods_values ||=
Array(cop_config.fetch('IgnoredMethods', [])) +
Array(cop_config.fetch('ExcludedMethods', []))
end
end

Expand Down
37 changes: 21 additions & 16 deletions spec/rubocop/cli/auto_gen_config_spec.rb
Expand Up @@ -951,29 +951,34 @@ def a; end
YAML
end

context 'when configurable parameter is an obsolete parameter' do
it 'displayed as a new parameter setting value without duplication' do
context 'when duplicated default configuration parameter' do
before do
RuboCop::ConfigLoader.default_configuration['Naming/MethodParameterName']
.merge!('AllowedNames' => %w[at by at])
end

it 'parameters are displayed without duplication' do
create_file('.rubocop.yml', <<~YAML)
AllCops:
NewCops: enable
Naming/MethodName:
# `IgnoredPatterns` is obsolete. `AllowedPatterns` is newly used.
IgnoredPatterns:
- change
- not_change
Naming/VariableName:
Enabled: false
YAML
create_file('example1.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])
create_file('example2.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])
create_file('example1.rb', <<~TEXT)
# frozen_string_literal: true
def bar(varOne, varTwo)
varOne + varTwo
end
TEXT

expect(cli.run(['--auto-gen-config'])).to eq(0)
File.readlines('.rubocop_todo.yml')
expect(File.readlines('.rubocop_todo.yml')[9..].join)
.to eq(<<~YAML)
# Configuration parameters: AllowedPatterns, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
# AllowedPatterns: change, not_change
Naming/MethodName:
EnforcedStyle: camelCase
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by
Naming/MethodParameterName:
Exclude:
- 'example1.rb'
YAML
end
end
Expand Down

0 comments on commit 54027a3

Please sign in to comment.