diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-10-05 12:59:52 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-10-05 19:58:31 +0900 |
| commit | 674e2ca9452121a3e3066e04ecd51ba8d863cf2b (patch) | |
| tree | 8cf1aef9a2402169f21e681f4a95576c2bd2c388 | |
| parent | 1dd11fe8c8a238ea88f5abbdb673de313a82ede2 (diff) | |
[ruby/pp] Reduce substring creations
https://github.com/ruby/pp/commit/fee2d39099
| -rw-r--r-- | lib/pp.rb | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -313,12 +313,10 @@ class PP < PrettyPrint # A pretty print for a pair of Hash def pp_hash_pair(k, v) if Symbol === k - sym_s = k.inspect - if sym_s[1].match?(/["$@!]/) || sym_s[-1].match?(/[%&*+\-\/<=>@\]^`|~]/) - text "#{k.to_s.inspect}:" - else - text "#{k}:" + if k.inspect.match?(%r[\A:["$@!]|[%&*+\-\/<=>@\]^`|~]\z]) + k = k.to_s.inspect end + text "#{k}:" else pp k text ' ' |
