From 0f11cda48ca73fdcdbbe9f72e185d017d218d196 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 11 Jun 2016 04:52:35 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ lib/forwardable.rb | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index acf0d73a0c..848d50a196 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jun 11 13:52:33 2016 Nobuyoshi Nakada + + * lib/forwardable.rb (_delegator_method): remove __send__ call if + possible, so that more optimizations will be enabled. + Sat Jun 11 11:24:36 2016 Nobuyoshi Nakada * enc/iso_8859.h (SHARP_s): name frequently used codepoint. 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;