Permalink
Browse files

Merge pull request #92 from nirvdrum/cache_symbols

Cache symbols while tokenizing.
  • Loading branch information...
2 parents 4be2aef + dd925d3 commit 74ed8ae1f11963ec84b23bb62296cd0b32194baa @tenderlove tenderlove committed Oct 13, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/psych/scalar_scanner.rb
@@ -16,12 +16,14 @@ class ScalarScanner
# 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 @@ def tokenize string
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

0 comments on commit 74ed8ae

Please sign in to comment.