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:
parent
85479b34f7
commit
40be4d4263
1 changed files with 2 additions and 2 deletions
|
@ -95,7 +95,7 @@ module Psych
|
||||||
if string.match?(/\A[-+]?\.\Z/)
|
if string.match?(/\A[-+]?\.\Z/)
|
||||||
string
|
string
|
||||||
else
|
else
|
||||||
Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1'))
|
Float(string.delete(',_').gsub(/\.([Ee]|$)/, '\1'))
|
||||||
end
|
end
|
||||||
elsif string.match?(integer_regex)
|
elsif string.match?(integer_regex)
|
||||||
parse_int string
|
parse_int string
|
||||||
|
@ -107,7 +107,7 @@ module Psych
|
||||||
###
|
###
|
||||||
# Parse and return an int from +string+
|
# Parse and return an int from +string+
|
||||||
def parse_int string
|
def parse_int string
|
||||||
Integer(string.gsub(/[,_]/, ''))
|
Integer(string.delete(',_'))
|
||||||
end
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
Loading…
Reference in a new issue