@@ -16,19 +16,19 @@ module Performance
1616 # send('do_something')
1717 # attr_accessor 'do_something'
1818 # instance_variable_get('@ivar')
19- # respond_to?("string_#{interpolation}")
2019 #
2120 # # good
2221 # send(:do_something)
2322 # attr_accessor :do_something
2423 # instance_variable_get(:@ivar)
25- # respond_to?(:"string_#{interpolation}")
2624 #
2725 # # good - these methods don't support namespaced symbols
2826 # const_get("#{module_path}::Base")
2927 # const_source_location("#{module_path}::Base")
3028 # const_defined?("#{module_path}::Base")
3129 #
30+ # # good - using a symbol when string interpolation is involved causes a performance regression.
31+ # respond_to?("string_#{interpolation}")
3232 #
3333 class StringIdentifierArgument < Base
3434 extend AutoCorrector
@@ -40,8 +40,6 @@ class StringIdentifierArgument < Base
4040 protected public public_constant module_function
4141 ] . freeze
4242
43- INTERPOLATION_IGNORE_METHODS = %i[ const_get const_source_location const_defined? ] . freeze
44-
4543 TWO_ARGUMENTS_METHOD = :alias_method
4644 MULTIPLE_ARGUMENTS_METHODS = %i[
4745 attr_accessor attr_reader attr_writer private private_constant
@@ -59,7 +57,7 @@ class StringIdentifierArgument < Base
5957 deprecate_constant remove_const ruby2_keywords define_singleton_method instance_variable_defined?
6058 instance_variable_get instance_variable_set method public_method public_send remove_instance_variable
6159 respond_to? send singleton_method __send__
62- ] + COMMAND_METHODS + INTERPOLATION_IGNORE_METHODS ) . freeze
60+ ] + COMMAND_METHODS ) . freeze
6361
6462 def on_send ( node )
6563 return if COMMAND_METHODS . include? ( node . method_name ) && node . receiver
@@ -83,13 +81,7 @@ def string_arguments(node)
8381 [ node . first_argument ]
8482 end
8583
86- arguments . compact . filter { |argument | string_argument_compatible? ( argument , node ) }
87- end
88-
89- def string_argument_compatible? ( argument , node )
90- return true if argument . str_type?
91-
92- argument . dstr_type? && INTERPOLATION_IGNORE_METHODS . none? { |method | node . method? ( method ) }
84+ arguments . compact . filter ( &:str_type? )
9385 end
9486
9587 def register_offense ( argument , argument_value )
0 commit comments