ruby-changes:25239
From: tenderlove <ko1@a...>
Date: Tue, 23 Oct 2012 06:25:00 +0900 (JST)
Subject: [ruby-changes:25239] tenderlove:r37291 (trunk): * ext/psych/lib/psych/scalar_scanner.rb: Cache symbols while
tenderlove 2012-10-23 06:24:50 +0900 (Tue, 23 Oct 2012) New Revision: 37291 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37291 Log: * ext/psych/lib/psych/scalar_scanner.rb: Cache symbols while tokenizing. Thanks Kevin Menard! Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/scalar_scanner.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37290) +++ ChangeLog (revision 37291) @@ -1,3 +1,8 @@ +Tue Oct 23 06:17:36 2012 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/scalar_scanner.rb: Cache symbols while + tokenizing. Thanks Kevin Menard! + Tue Oct 23 06:15:40 2012 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/scalar_scanner.rb: Updated the RegExp to catch Index: ext/psych/lib/psych/scalar_scanner.rb =================================================================== --- ext/psych/lib/psych/scalar_scanner.rb (revision 37290) +++ ext/psych/lib/psych/scalar_scanner.rb (revision 37291) @@ -16,12 +16,14 @@ # 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/