[ruby/psych] Use String#match? over String#=~ when applicable

Save on allocating useless `MatchData` instances.

https://github.com/ruby/psych/commit/b2d9f16e58
This commit is contained in:
Jean Boussier 2024-09-24 15:20:08 -04:00 committed by git
parent e956ce32c8
commit d31378dc91
2 changed files with 4 additions and 4 deletions

View File

@ -36,7 +36,7 @@ module Psych
unless @domain_types.empty? || !target.tag
key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
key = "tag:#{key}" unless key.match?(/^(?:tag:|x-private)/)
if @domain_types.key? key
value, block = @domain_types[key]

View File

@ -261,7 +261,7 @@ module Psych
style = Nodes::Scalar::LITERAL
plain = false
quote = false
elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
elsif o.match?(/\n(?!\Z)/) # match \n except blank line at the end of string
style = Nodes::Scalar::LITERAL
elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED
@ -272,9 +272,9 @@ module Psych
style = Nodes::Scalar::DOUBLE_QUOTED
elsif @line_width && o.length > @line_width
style = Nodes::Scalar::FOLDED
elsif o =~ /^[^[:word:]][^"]*$/
elsif o.match?(/^[^[:word:]][^"]*$/)
style = Nodes::Scalar::DOUBLE_QUOTED
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/.match?(o)
style = Nodes::Scalar::SINGLE_QUOTED
end