[前][次][番号順一覧][スレッド一覧]

ruby-changes:43302

From: nobu <ko1@a...>
Date: Sat, 11 Jun 2016 13:52:40 +0900 (JST)
Subject: [ruby-changes:43302] nobu:r55376 (trunk): forwardable.rb: optimize awy __send__

nobu	2016-06-11 13:52:35 +0900 (Sat, 11 Jun 2016)

  New Revision: 55376

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55376

  Log:
    forwardable.rb: optimize awy __send__
    
    * lib/forwardable.rb (_delegator_method): remove __send__ call if
      possible, so that more optimizations will be enabled.

  Modified files:
    trunk/ChangeLog
    trunk/lib/forwardable.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55375)
+++ ChangeLog	(revision 55376)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 11 13:52:33 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <nobu@r...>
 
 	* enc/iso_8859.h (SHARP_s): name frequently used codepoint.
Index: lib/forwardable.rb
===================================================================
--- lib/forwardable.rb	(revision 55375)
+++ lib/forwardable.rb	(revision 55376)
@@ -195,13 +195,23 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L195
       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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]