Skip to content

Commit

Permalink
Use Regexp#match? to avoid extra allocations
Browse files Browse the repository at this point in the history
`#=~` builds `MatchData`, requiring extra allocations as compared to
`#match?`, which returns a boolean w/o having to build the `MatchData`.
  • Loading branch information
stevenharman committed Aug 18, 2020
1 parent 333d874 commit 158f58a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def self.encode_www_form_component(str, enc=nil)
#
# 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

Expand Down

0 comments on commit 158f58a

Please sign in to comment.