Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #92 from nirvdrum/cache_symbols

Cache symbols while tokenizing.
  • Loading branch information...
commit 74ed8ae1f11963ec84b23bb62296cd0b32194baa 2 parents 4be2aef + dd925d3
@tenderlove tenderlove authored
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/psych/scalar_scanner.rb
View
6 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
Please sign in to comment.
Something went wrong with that request. Please try again.