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

ruby-changes:65937

From: Steven <ko1@a...>
Date: Thu, 22 Apr 2021 14:57:37 +0900 (JST)
Subject: [ruby-changes:65937] bbee6968f8 (master): [ruby/uri] Use Regexp#match? to avoid extra allocations

https://git.ruby-lang.org/ruby.git/commit/?id=bbee6968f8

From bbee6968f82137645f2029379906f5b5d3911ead Mon Sep 17 00:00:00 2001
From: Steven Harman <steven@h...>
Date: Tue, 18 Aug 2020 13:49:08 -0400
Subject: [ruby/uri] Use Regexp#match? to avoid extra allocations

`#=~` builds `MatchData`, requiring extra allocations as compared to
`#match?`, which returns a boolean w/o having to build the `MatchData`.

https://github.com/ruby/uri/commit/158f58a9cc
---
 lib/uri/common.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index d818592..915c0e9 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -321,7 +321,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L321
   #
   # See URI.encode_www_form_component, URI.decode_www_form.
   def self.decode_www_form_component(str, enc=Encoding::UTF_8)
-    raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
+    raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/.match?(str)
     str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
   end
 
-- 
cgit v1.1


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

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