On Tue, Aug 3, 2010 at 1:08 PM, Terry Brown <[email protected]> wrote:

> Looks like a useful method.  Wouldn't passing in an iterator / list be more 
> versatile?  For example the context menu multiple selected nodes delete (and 
> the unimplemented cut/copy) could use it then.

Imo, the present code is easy enough to use.

More to the point, today's work shows that using the iterator won't
work. In fact, *not* using iterators is an extremely important
optimization.

The essential problem is that iterators assume that the tree they are
iterating over will not change.  Absolutely all bets are off if that
isn't so.  To avoid this problem, one could "capture" the iterator as
follows:

    positions = [z.copy() for z in theIter]
    ...
    for p in positions:

Alas, this is a serious gc bug:  it creates one position for every
position in the traversal.

I then attempted to compute the first and afterLast nodes directly
from the iterator.  But how to do this?

Wrong 1:

for p in theIter:
    if not first: first = p.copy()
afterLast = p.copy # Wrong: p is undefined outside theIter.

Wrong 2:

for p in theIter:
   if not first: first = p.copy()
   last = p.copy() # Wrong: the same gc bug in a different form.
afterLast = last.threadNext()

Furthermore, both of these wrong approaches will waste a lot of time
iterating through an entire tree.

In short, we had best stick with what we have.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to