* 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
This commit is contained in:
parent
ca0cf16734
commit
6c6d4568e8
@ -1,3 +1,8 @@
|
|||||||
|
Tue Oct 23 06:17:36 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* ext/psych/lib/psych/scalar_scanner.rb: Cache symbols while
|
||||||
|
tokenizing. Thanks Kevin Menard!
|
||||||
|
|
||||||
Tue Oct 23 06:15:40 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
Tue Oct 23 06:15:40 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/lib/psych/scalar_scanner.rb: Updated the RegExp to catch
|
* ext/psych/lib/psych/scalar_scanner.rb: Updated the RegExp to catch
|
||||||
|
@ -16,12 +16,14 @@ module Psych
|
|||||||
# Create a new scanner
|
# Create a new scanner
|
||||||
def initialize
|
def initialize
|
||||||
@string_cache = {}
|
@string_cache = {}
|
||||||
|
@symbol_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tokenize +string+ returning the ruby object
|
# Tokenize +string+ returning the ruby object
|
||||||
def tokenize string
|
def tokenize string
|
||||||
return nil if string.empty?
|
return nil if string.empty?
|
||||||
return string if @string_cache.key?(string)
|
return string if @string_cache.key?(string)
|
||||||
|
return @symbol_cache[string] if @symbol_cache.key?(string)
|
||||||
|
|
||||||
case string
|
case string
|
||||||
# Check for a String type, being careful not to get caught by hash keys, hex values, and
|
# 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
|
0.0 / 0.0
|
||||||
when /^:./
|
when /^:./
|
||||||
if string =~ /^:(["'])(.*)\1/
|
if string =~ /^:(["'])(.*)\1/
|
||||||
$2.sub(/^:/, '').to_sym
|
@symbol_cache[string] = $2.sub(/^:/, '').to_sym
|
||||||
else
|
else
|
||||||
string.sub(/^:/, '').to_sym
|
@symbol_cache[string] = string.sub(/^:/, '').to_sym
|
||||||
end
|
end
|
||||||
when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
|
when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
|
||||||
i = 0
|
i = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user