Skip to content

Commit 158f58a

Browse files
committed
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`.
1 parent 333d874 commit 158f58a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: lib/uri/common.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def self.encode_www_form_component(str, enc=nil)
397397
#
398398
# See URI.encode_www_form_component, URI.decode_www_form.
399399
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
400-
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
400+
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/.match?(str)
401401
str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
402402
end
403403

0 commit comments

Comments
 (0)