1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use bind_call(obj, ...) instead of bind(obj).call(...)

`bind_call(obj, ...)` is a faster alternative to `bind(obj).call(...)`.

https://bugs.ruby-lang.org/issues/15955

Also, enable `Performance/BindCall` cop to detect those in the future.
This commit is contained in:
Ryuta Kamizono 2021-02-08 16:57:53 +09:00
parent 25af5e9ff8
commit 6515d6985d
4 changed files with 6 additions and 3 deletions

View file

@ -250,6 +250,9 @@ Style/ColonMethodCall:
Style/TrivialAccessors:
Enabled: true
Performance/BindCall:
Enabled: true
Performance/FlatMap:
Enabled: true

View file

@ -31,7 +31,7 @@ module ActiveRecord
end
def inspect
Kernel.instance_method(:inspect).bind(self).call
Kernel.instance_method(:inspect).bind_call(self)
end
def changed_in_place?(raw_old_value, value)

View file

@ -814,7 +814,7 @@ module ActiveSupport #:nodoc:
# Returns the original name of a class or module even if `name` has been
# overridden.
def real_mod_name(mod)
UNBOUND_METHOD_MODULE_NAME.bind(mod).call
UNBOUND_METHOD_MODULE_NAME.bind_call(mod)
end
end
end

View file

@ -62,7 +62,7 @@ module ActiveSupport
target_module.module_eval do
redefine_method(method_name) do |*args, &block|
deprecator.deprecation_warning(method_name, message)
method.bind(self).call(*args, &block)
method.bind_call(self, *args, &block)
end
ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
end