diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-22 08:48:44 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-22 08:48:44 +0000 |
commit | cfe937b9b20fb356cf820c932616b6cdb603d4a1 (patch) | |
tree | 8d032e0e0438fd6683386e3767d6caf1b50cdae7 /lib/forwardable.rb | |
parent | 228b29a697f719f60f0a62e3cdf1bb8c991beba3 (diff) |
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].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/forwardable.rb')
-rw-r--r-- | lib/forwardable.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb index d7116ed1bc..0f8807aac1 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -102,6 +102,8 @@ module Forwardable # 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 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 # 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 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 |