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

ruby-changes:27823

From: nobu <ko1@a...>
Date: Fri, 22 Mar 2013 17:48:54 +0900 (JST)
Subject: [ruby-changes:27823] nobu:r39875 (trunk): forwardable.rb: reduce allocations in def_delegators

nobu	2013-03-22 17:48:44 +0900 (Fri, 22 Mar 2013)

  New Revision: 39875

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39875

  Log:
    forwardable.rb: reduce allocations in def_delegators
    
    * lib/forwardable.rb (Forwardable::FILE_REGEXP): create regexp object
      outside sources for eval, to reduce allocations in def_delegators
      wrappers.  //o option does not make each regexps shared.  patch by
      tmm1 (Aman Gupta) in [ruby-core:53620] [Bug #8143].

  Modified files:
    trunk/ChangeLog
    trunk/lib/forwardable.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39874)
+++ ChangeLog	(revision 39875)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Mar 22 17:48:34 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/forwardable.rb (Forwardable::FILE_REGEXP): create regexp object
+	  outside sources for eval, to reduce allocations in def_delegators
+	  wrappers.  //o option does not make each regexps shared.  patch by
+	  tmm1 (Aman Gupta) in [ruby-core:53620] [Bug #8143].
+
 Fri Mar 22 17:38:42 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* load.c (rb_feature_p), vm_core.h (rb_vm_struct): turn
Index: lib/forwardable.rb
===================================================================
--- lib/forwardable.rb	(revision 39874)
+++ lib/forwardable.rb	(revision 39875)
@@ -102,6 +102,8 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L102
   # Version of +forwardable.rb+
   FORWARDABLE_VERSION = "1.1.0"
 
+  FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}"
+
   @debug = nil
   class << self
     # If true, <tt>__FILE__</tt> will remain in the backtrace in the event an
@@ -170,7 +172,7 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L172
         begin
           #{accessor}.__send__(:#{method}, *args, &block)
         rescue Exception
-          $@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
+          $@.delete_if{|s| Forwardable::FILE_REGEXP =~ s} unless Forwardable::debug
           ::Kernel::raise
         end
       end
@@ -203,14 +205,14 @@ end https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L205
 #       puts "serviced!"
 #     end
 #   end
-#   
+#
 #   module Facade
 #     extend SingleForwardable
 #     def_delegator :Implementation, :service
 #   end
 #
 #   Facade.service #=> serviced!
-#   
+#
 # If you want to use both Forwardable and SingleForwardable, you can
 # use methods def_instance_delegator and def_single_delegator, etc.
 module SingleForwardable
@@ -262,7 +264,7 @@ module SingleForwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L264
         begin
           #{accessor}.__send__(:#{method}, *args, &block)
         rescue Exception
-          $@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
+          $@.delete_if{|s| Forwardable::FILE_REGEXP =~ s} unless Forwardable::debug
           ::Kernel::raise
         end
       end

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

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