On Wednesday, December 18, 2013 8:34:21 AM UTC-6, Edward K. Ream wrote:

> Rev 6432 contains the prototype of a simpler, faster, more flexible 
importer for Python files...

> This is the first of two "risky" projects needed to make @auto pretty 
much a drop-in replacement for @file...

> The other risky part of the puzzle is the code that will reconstitute 
clone links from nodes in the .leo file to nodes in @auto trees.

Here is p._relinkAsCloneOf, a new method that *replaces* the vnode at 
position p with the vnode at position p2, thereby making p.v a clone of 
p2.v:

    def _relinkAsCloneOf(self,p2):
        '''A low-level method to replace p.v by a p2.v.'''
        p = self
        v,v2 = p.v,p2.v
        parent_v = p._parentVnode()
        assert parent_v.children[p._childIndex] == v
        parent_v.children[p._childIndex] = v2
        v2.parents.append(parent_v)
        p.v = p2.v # Not strictly needed, but keeps p accurate.

It took me awhile to realize that the code simply needs to change all links 
to p to p2.  This is easy, at least for the importer, because p is *not* a 
clone.  So the only link to p is in the children array of its (single) 
parent vnode.  In addition, v2.parents must be updated.  As you can see, 
the code will be extremely fast.

This code passes a pretty hefty unit test.  It seems like the crucial part 
of relinking is in place.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to