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

ruby-changes:45182

From: nobu <ko1@a...>
Date: Tue, 3 Jan 2017 17:40:59 +0900 (JST)
Subject: [ruby-changes:45182] nobu:r57255 (trunk): forwardable.rb: use defined?

nobu	2017-01-03 17:40:51 +0900 (Tue, 03 Jan 2017)

  New Revision: 57255

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

  Log:
    forwardable.rb: use defined?
    
    * lib/forwardable.rb (_delegator_method): use defined? operator
      instead of binding and calling unbound Kernel#respond_to?.  a
      remedy for an performance bottleneck.

  Modified files:
    trunk/lib/forwardable.rb
Index: lib/forwardable.rb
===================================================================
--- lib/forwardable.rb	(revision 57254)
+++ lib/forwardable.rb	(revision 57255)
@@ -131,7 +131,7 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L131
   #
   def instance_delegate(hash)
     hash.each{ |methods, accessor|
-      methods = [methods] unless methods.respond_to?(:each)
+      methods = [methods] unless defined?(methods.each)
       methods.each{ |method|
         def_instance_delegator(accessor, method)
       }
@@ -204,7 +204,7 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L204
       mesg = "#{Module === obj ? obj : obj.class}\##{ali} at #{loc.path}:#{loc.lineno} forwarding to private method "
       method_call = "#{<<-"begin;"}\n#{<<-"end;".chomp}"
         begin;
-          unless ::Kernel.instance_method(:respond_to?).bind(_).call(:"#{method}")
+          unless defined? _.#{method}
             ::Kernel.warn "\#{caller_locations(1)[0]}: "#{mesg.dump}"\#{_.class}"'##{method}'
             _#{method_call}
           else
@@ -262,7 +262,7 @@ module SingleForwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L262
   #
   def single_delegate(hash)
     hash.each{ |methods, accessor|
-      methods = [methods] unless methods.respond_to?(:each)
+      methods = [methods] unless defined?(methods.each)
       methods.each{ |method|
         def_single_delegator(accessor, method)
       }

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

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