summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-04-26 13:26:14 +0200
committerJean Boussier <jean.boussier@gmail.com>2019-04-26 18:28:59 +0200
commitd60a8074ce9b70543a5a8b79cfae87a9ed97b316 (patch)
tree5811dcc25ea1ef4981004e409c62f99bc7b88c17
parentf3a37e6bc1c2a98bfc9fafc389ea05622c744af9 (diff)
downloadpsych-d60a8074ce9b70543a5a8b79cfae87a9ed97b316.tar.gz
Reduce string allocations in scalar_scanner
-rw-r--r--.travis.yml1
-rw-r--r--appveyor.yml2
-rw-r--r--lib/psych/scalar_scanner.rb32
3 files changed, 15 insertions, 20 deletions
diff --git a/.travis.yml b/.travis.yml
index 6ad43f6..7f1a80c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,4 @@
rvm:
- - 2.3.8
- 2.4.5
- 2.5.3
- 2.6.0
diff --git a/appveyor.yml b/appveyor.yml
index 4df19c9..90ed36c 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -10,8 +10,6 @@ test_script:
deploy: off
environment:
matrix:
- - ruby_version: "23"
- - ruby_version: "23-x64"
- ruby_version: "24"
- ruby_version: "24-x64"
- ruby_version: "25"
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb
index 29c156c..f89aa68 100644
--- a/lib/psych/scalar_scanner.rb
+++ b/lib/psych/scalar_scanner.rb
@@ -34,68 +34,66 @@ module Psych
return string if @string_cache.key?(string)
return @symbol_cache[string] if @symbol_cache.key?(string)
- case string
# Check for a String type, being careful not to get caught by hash keys, hex values, and
# special floats (e.g., -.inf).
- when /^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/, /\n/
+ if string.match?(/^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/) || string.match?(/\n/)
if string.length > 5
@string_cache[string] = true
return string
end
- case string
- when /^[^ytonf~]/i
+ if string.match?(/^[^ytonf~]/i)
@string_cache[string] = true
string
- when '~', /^null$/i
+ elsif string == '~' || string.match?(/^null$/i)
nil
- when /^(yes|true|on)$/i
+ elsif string.match?(/^(yes|true|on)$/i)
true
- when /^(no|false|off)$/i
+ elsif string.match?(/^(no|false|off)$/i)
false
else
@string_cache[string] = true
string
end
- when TIME
+ elsif string.match?(TIME)
begin
parse_time string
rescue ArgumentError
string
end
- when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/
+ elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/)
require 'date'
begin
class_loader.date.strptime(string, '%Y-%m-%d')
rescue ArgumentError
string
end
- when /^\.inf$/i
+ elsif string.match?(/^\.inf$/i)
Float::INFINITY
- when /^-\.inf$/i
+ elsif string.match?(/^-\.inf$/i)
-Float::INFINITY
- when /^\.nan$/i
+ elsif string.match?(/^\.nan$/i)
Float::NAN
- when /^:./
+ elsif string.match?(/^:./)
if string =~ /^:(["'])(.*)\1/
@symbol_cache[string] = class_loader.symbolize($2.sub(/^:/, ''))
else
@symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
end
- when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/
+ elsif string.match?(/^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/)
i = 0
string.split(':').each_with_index do |n,e|
i += (n.to_i * 60 ** (e - 2).abs)
end
i
- when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/
+ elsif string.match?(/^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/)
i = 0
string.split(':').each_with_index do |n,e|
i += (n.to_f * 60 ** (e - 2).abs)
end
i
- when FLOAT
- if string =~ /\A[-+]?\.\Z/
+ elsif string.match?(FLOAT)
+ if string.match?(/\A[-+]?\.\Z/)
@string_cache[string] = true
string
else