diff options
| author | Jeremy Evans <code@jeremyevans.net> | 2024-08-19 15:03:43 -0700 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-11-24 08:44:28 +0000 |
| commit | aeb7689e696540f3f96bad87efc91ba2b4187c99 (patch) | |
| tree | 7c2edd148946652719b2e4024dd544bbbc964038 | |
| parent | 45fcb9d590d36c469e7fa18790fafd51809943ee (diff) | |
[ruby/forwardable] Use generic argument forwarding (...) instead of ruby2_keywords on Ruby 2.7+
On Ruby 3.4+, generic argument forwarding is significantly faster
as it does not allocate.
https://github.com/ruby/forwardable/commit/b606c3bf0a
| -rw-r--r-- | lib/forwardable.rb | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb index 5652e72864..76267c2cd1 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -192,9 +192,7 @@ module Forwardable # If it's not a class or module, it's an instance mod = Module === self ? self : singleton_class - ret = mod.module_eval(&gen) - mod.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' - ret + mod.module_eval(&gen) end alias delegate instance_delegate @@ -211,7 +209,8 @@ module Forwardable accessor = "#{accessor}()" end - method_call = ".__send__(:#{method}, *args, &block)" + args = RUBY_VERSION >= '2.7' ? '...' : '*args, &block' + method_call = ".__send__(:#{method}, #{args})" if _valid_method?(method) loc, = caller_locations(2,1) pre = "_ =" @@ -222,7 +221,7 @@ module Forwardable ::Kernel.warn #{mesg.dump}"\#{_.class}"'##{method}', uplevel: 1 _#{method_call} else - _.#{method}(*args, &block) + _.#{method}(#{args}) end end; end @@ -230,7 +229,7 @@ module Forwardable _compile_method("#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1) begin; proc do - def #{ali}(*args, &block) + def #{ali}(#{args}) #{pre} begin #{accessor} @@ -312,9 +311,7 @@ module SingleForwardable def def_single_delegator(accessor, method, ali = method) gen = Forwardable._delegator_method(self, accessor, method, ali) - ret = instance_eval(&gen) - singleton_class.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' - ret + instance_eval(&gen) end alias delegate single_delegate |
