diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-22 21:24:50 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-22 21:24:50 +0000 |
commit | 6c6d4568e8b8c8667c0b57ca6e1b5ba5d7acbbe3 (patch) | |
tree | 91f4f0146b271ac4e5a2e48528fd7a30f41d12b5 /ext | |
parent | ca0cf1673409cae3f8425d6235dbcce9709fa61b (diff) | |
download | ruby-6c6d4568e8b8c8667c0b57ca6e1b5ba5d7acbbe3.tar.gz |
* ext/psych/lib/psych/scalar_scanner.rb: Cache symbols while
tokenizing. Thanks Kevin Menard!
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/psych/lib/psych/scalar_scanner.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb index 9130746347..41e889a528 100644 --- a/ext/psych/lib/psych/scalar_scanner.rb +++ b/ext/psych/lib/psych/scalar_scanner.rb @@ -16,12 +16,14 @@ module Psych # Create a new scanner def initialize @string_cache = {} + @symbol_cache = {} end # Tokenize +string+ returning the ruby object def tokenize string return nil if string.empty? 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 @@ -67,9 +69,9 @@ module Psych 0.0 / 0.0 when /^:./ if string =~ /^:(["'])(.*)\1/ - $2.sub(/^:/, '').to_sym + @symbol_cache[string] = $2.sub(/^:/, '').to_sym else - string.sub(/^:/, '').to_sym + @symbol_cache[string] = string.sub(/^:/, '').to_sym end when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/ i = 0 |