Skip to content

Commit 4400c0c

Browse files
authored
Merge pull request #530 from MSP-Greg/gsub2tr
scalar_scanner.rb - delete is typically 4 to 5 times faster than gsub
2 parents 1ca1d2f + 8533be8 commit 4400c0c

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)