Hi --

On Tue, 18 Jan 2005, David Tran wrote:

> Quick review, find a performance and memory issue ...
>
> The code:
>    if get_answer
>      @node[0,1] = [question, [animal], @node.dup]
>    else
>      @node[0,1] = [question, @node.dup, [animal]]
>    end
>
> is better replace by:
>    temp = @node
>    if get_answer
>      @node[0,1] = [question, [animal], temp]
>    else
>      @node[0,1] = [question, temp, [animal]]
>    end

I believe that the second one is equivalent to:

   if get_answer
     @node[0,1] = [question, [animal], @node]
   else
     @node[0,1] = [question, @node, [animal]]
   end

since temp is just another reference to the object that @node is a
reference to, not to a copy of that object.  So you end up with a
recursive data structure.


David

-- 
David A. Black
dblack / wobblini.net