[前][次][番号順一覧][スレッド一覧]

ruby-changes:27091

From: tenderlove <ko1@a...>
Date: Fri, 8 Feb 2013 09:03:14 +0900 (JST)
Subject: [ruby-changes:27091] tenderlove:r39143 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference

tenderlove	2013-02-08 08:52:01 +0900 (Fri, 08 Feb 2013)

  New Revision: 39143

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39143

  Log:
    * ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
      ids to be sequential numbers.

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/yaml_tree.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39142)
+++ ChangeLog	(revision 39143)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Feb  8 08:50:42 2013  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
+	  ids to be sequential numbers.
+
 Fri Feb  8 07:47:56 2013  Eric Hodel  <drbrain@s...>
 
 	* lib/rubygems/package/old.rb:  Disallow installation of old-format
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 39142)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 39143)
@@ -8,6 +8,30 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L8
     #   builder.tree # => #<Psych::Nodes::Stream .. }
     #
     class YAMLTree < Psych::Visitors::Visitor
+      class Registrar # :nodoc:
+        def initialize
+          @obj_to_id   = {}
+          @obj_to_node = {}
+          @counter     = 0
+        end
+
+        def register target, node
+          @obj_to_node[target.object_id] = node
+        end
+
+        def key? target
+          @obj_to_node.key? target.object_id
+        end
+
+        def id_for target
+          @obj_to_id[target.object_id] ||= (@counter += 1)
+        end
+
+        def node_for target
+          @obj_to_node[target.object_id]
+        end
+      end
+
       attr_reader :started, :finished
       alias :finished? :finished
       alias :started? :started
@@ -17,7 +41,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L41
         @started  = false
         @finished = false
         @emitter  = emitter
-        @st       = {}
+        @st       = Registrar.new
         @ss       = ss
         @options  = options
         @coders   = []
@@ -72,9 +96,9 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L96
 
       def accept target
         # return any aliases we find
-        if @st.key? target.object_id
-          oid         = target.object_id
-          node        = @st[oid]
+        if @st.key? target
+          oid         = @st.id_for target
+          node        = @st.node_for target
           anchor      = oid.to_s
           node.anchor = anchor
           return @emitter.alias anchor
@@ -410,7 +434,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L434
       end
 
       def register target, yaml_obj
-        @st[target.object_id] = yaml_obj
+        @st.register target, yaml_obj
         yaml_obj
       end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]