1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[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
This commit is contained in:
Steven Harman 2020-08-18 13:49:08 -04:00 committed by Hiroshi SHIBATA
parent 291cfa7125
commit bbee6968f8

View file

@ -321,7 +321,7 @@ module URI
# #
# See URI.encode_www_form_component, URI.decode_www_form. # See URI.encode_www_form_component, URI.decode_www_form.
def self.decode_www_form_component(str, enc=Encoding::UTF_8) 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) str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
end end