def mkDirty(v):
v.setDirty()
for v1 in v.parents:
mkDirty(v1)
calls[n=100000] avg:0.033ms
Today I have looked in p.setDirty and I've found that it is overly complicated and as one might expect accordingly expensive.
# module leoNodes
# class Position
def setAllAncestorAtFileNodesDirty(self, setDescendentsDirty=False)
# module leo.core.commanderOutlineCommands
# command 'insert-node-before'@g.commander_command('insert-node-before')
@g.commander_command('insert-node-before')
def insertHeadlineBefore(self, event=None):
'''Insert a node before the presently selected node.'''
c, current, u = self, self.p, self.undoer
op_name = 'Insert Node Before'
if not current: return
# Can not insert before the base of a hoist.
if c.hoistStack and current == c.hoistStack[-1].p:
g.warning('can not insert a node before the base of a hoist')
return
c.endEditing()
undoData = u.beforeInsertNode(current)
p = current.insertBefore()
g.doHook('create-node', c=c, p=p)
p.setDirty(setDescendentsDirty=False)
dirtyVnodeList = p.setAllAncestorAtFileNodesDirty()
c.setChanged(True)
u.afterInsertNode(p, op_name, undoData, dirtyVnodeList=dirtyVnodeList)
c.redrawAndEdit(p, selectAll=True)
return p
p.setDirty(setDescendentsDirty=False)
dirtyVnodeList = p.setAllAncestorAtFileNodesDirty()
Have you considered clones?Edward
def mkDirty(v):
It seems that p.setDirty propagates dirty status not only to the ancestors but also to the all descendant nodes as well, nodes that are roots of external files (v.isAnyAtFileNode()). At first I thought this was unnecessary, but then I realized this is probably to allow that change in the ancestor can change resulting path of the descendant file nodes which would require those nodes to be written on the next save operation.
If this is the reason to propagate dirty status down the tree, then perhaps it can be skipped if this node doesn't contain at-path or any other directive that might cause need for writing descendant file nodes. That would be almost always the case.
Changing for example top level node "Code" in LeoPyRef.leo causes more than 160 files to be set dirty on the next save command, which seems to me wrong.