aboutsummaryrefslogtreecommitdiffstats
path: root/lib/forwardable.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-11 04:52:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-11 04:52:35 +0000
commit8022e615a36f892021fa27e478f63c1416f72fde (patch)
tree3ba6fa12639efff4d80631963f7d3aa024d1908c /lib/forwardable.rb
parent0cfe60ecebea5808c8d97f3c98227c37d327d67d (diff)
downloadruby-8022e615a36f892021fa27e478f63c1416f72fde.tar.gz
forwardable.rb: optimize awy __send__
* lib/forwardable.rb (_delegator_method): remove __send__ call if possible, so that more optimizations will be enabled. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/forwardable.rb')
-rw-r--r--lib/forwardable.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index 26c5bf7463..fce560db81 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -195,13 +195,23 @@ module Forwardable
accessor = "#{accessor}()"
end
+ unless begin
+ iseq = RubyVM::InstructionSequence
+ .compile("().#{method}", nil, nil, 0, false)
+ rescue SyntaxError
+ else
+ iseq.to_a.dig(-1, 1, 1, :mid) == method.to_sym
+ end
+ method = "__send__ :#{method},"
+ end
+
line_no = __LINE__+1; str = "#{<<-"begin;"}\n#{<<-"end;"}"
begin;
proc do
def #{ali}(*args, &block)
begin
#{accessor}
- end.__send__ :#{method}, *args, &block
+ end.#{method} *args, &block
end
end
end;