Skip to content

Commit 8533be8

Browse files
committed
tr is typically 4 to 5 times faster than gsub
1 parent 79d4b99 commit 8533be8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/psych/scalar_scanner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def tokenize string
9595
if string.match?(/\A[-+]?\.\Z/)
9696
string
9797
else
98-
Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1'))
98+
Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
9999
end
100100
elsif string.match?(integer_regex)
101101
parse_int string
@@ -107,7 +107,7 @@ def tokenize string
107107
###
108108
# Parse and return an int from +string+
109109
def parse_int string
110-
Integer(string.gsub(/[,_]/, ''))
110+
Integer(string.delete(',_'))
111111
end
112112

113113
###

0 commit comments

Comments
 (0)