From 674e2ca9452121a3e3066e04ecd51ba8d863cf2b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 5 Oct 2025 12:59:52 +0900 Subject: [ruby/pp] Reduce substring creations https://github.com/ruby/pp/commit/fee2d39099 --- lib/pp.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/pp.rb b/lib/pp.rb index 2c7f41eadd..e790f499d4 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -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 ' ' -- cgit v1.2.3