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:
parent
291cfa7125
commit
bbee6968f8
1 changed files with 1 additions and 1 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue