From b28b192af194ca63fad6e3cde3b56b78f9132cac Mon Sep 17 00:00:00 2001 From: Roque Pinel Date: Mon, 8 Jun 2015 21:14:33 -0400 Subject: Use block variable instead of global MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```ruby Benchmark.ips do |x| x.report("$&") { "foo".gsub(/f/) { $&.hex } } x.report("block var") { "foo".gsub(/f/) { |match| match.hex } } end ``` ``` Calculating ------------------------------------- $& 23.271k i/100ms block var 24.804k i/100ms ------------------------------------------------- $& 321.981k (± 7.4%) i/s - 1.606M block var 324.949k (± 9.2%) i/s - 1.612M ``` --- activesupport/lib/active_support/core_ext/uri.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb index bfe0832b37..0b2ff817c3 100644 --- a/activesupport/lib/active_support/core_ext/uri.rb +++ b/activesupport/lib/active_support/core_ext/uri.rb @@ -12,7 +12,7 @@ unless str == parser.unescape(parser.escape(str)) # YK: My initial experiments say yes, but let's be sure please enc = str.encoding enc = Encoding::UTF_8 if enc == Encoding::US_ASCII - str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc) + str.gsub(escaped) { |match| [match[1, 2].hex].pack('C') }.force_encoding(enc) end end end -- cgit v1.2.3