only marking/counting occurences that are actually referenced, so numbers stay smaller

This commit is contained in:
Torsten Ruger 2014-08-18 17:25:49 +03:00
parent e13801c764
commit 9d5f62eded
3 changed files with 7 additions and 8 deletions

View File

@ -17,12 +17,12 @@ module Sof
if( occurence = @objects[object] )
#puts "reset level #{level} at #{occurence.level}"
occurence.level = level if occurence.level > level
occurence.referenced = true
occurence.referenced = @counter
@counter = @counter + 1
return
end
o = Occurence.new( object , @counter , level )
o = Occurence.new( object , level )
@objects[object] = o
@counter = @counter + 1
attributes = attributes_for(object)
attributes.each do |a|
val = get_value( object , a)

View File

@ -1,12 +1,11 @@
module Sof
class Occurence
def initialize object , number , level
def initialize object , level
@object = object
@number = number
@level = level
end
attr_reader :object , :number
attr_reader :object
attr_accessor :level , :referenced
end

View File

@ -20,9 +20,9 @@ module Sof
raise "no object #{object}" unless occurence
if(level > occurence.level )
#puts "level #{level} at #{occurence.level}"
return SimpleNode.new("*#{occurence.number}")
return SimpleNode.new("*#{occurence.referenced}")
end
ref = occurence.referenced ? occurence.number : nil
ref = occurence.referenced
if(object.respond_to? :to_sof_node) #mainly meant for arrays and hashes
object.to_sof_node(self , level , ref )
else