1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/psych] tr is typically 4 to 5 times faster than gsub

https://github.com/ruby/psych/commit/8533be8fe7
This commit is contained in:
MSP-Greg 2021-12-25 12:12:21 -06:00 committed by git
parent 85479b34f7
commit 40be4d4263

View file

@ -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
###