diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2024-09-24 15:20:08 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-09-24 19:25:40 +0000 |
| commit | d31378dc919cd3f39ee194f452b9dbc5942bb89d (patch) | |
| tree | ee272df9c1532a1d325af8285e97c88a8f70b5df /ext | |
| parent | e956ce32c8f7d1b1c57ed109f91979173ff22c36 (diff) | |
[ruby/psych] Use `String#match?` over `String#=~` when applicable
Save on allocating useless `MatchData` instances.
https://github.com/ruby/psych/commit/b2d9f16e58
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 2 | ||||
| -rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index f0fda9bdbc..9e4da5ef0d 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -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] diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index a2ebc4d781..e27c927996 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -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 |
