From 40be4d4263e77b6ce31144b1f49892c11ff53bbd Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Sat, 25 Dec 2021 12:12:21 -0600 Subject: [PATCH] [ruby/psych] tr is typically 4 to 5 times faster than gsub https://github.com/ruby/psych/commit/8533be8fe7 --- ext/psych/lib/psych/scalar_scanner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb index 58deea3baa..b50667c315 100644 --- a/ext/psych/lib/psych/scalar_scanner.rb +++ b/ext/psych/lib/psych/scalar_scanner.rb @@ -95,7 +95,7 @@ module Psych if string.match?(/\A[-+]?\.\Z/) string else - Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1')) + Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1')) end elsif string.match?(integer_regex) parse_int string @@ -107,7 +107,7 @@ module Psych ### # Parse and return an int from +string+ def parse_int string - Integer(string.gsub(/[,_]/, '')) + Integer(string.delete(',_')) end ###