A better implementation is below (tree_at_vnode). Incidentally, the
script below also shows how to save the leo document in json format,
for use from javascript :-).
QQQ
import json
def tree_at_vnode(v):
'''Create a recursive list describing a tree
for use by v.createOutlineFromCacheList.
'''
return [v.h,v.b,v.gnx, [tree_at_vnode(v2) for v2 in v.children]]
tree = tree_at_vnode(c.hiddenRootNode)
f = open("/tmp/leodoc.json","w")
json.dump(tree, f)
QQQ
--
Ville M. Vainio
http://tinyurl.com/vainio
Currently p.makeCacheList() is somewhat inefficient, as it goes
through positions unnecessarily.
def tree_at_vnode(v):
return [v.h,v.b,v.gnx, [tree_at_vnode(v2) for v2 in v.children]]
>> def tree_at_vnode(v):
>> return [v.h,v.b,v.gnx, [tree_at_vnode(v2) for v2 in v.children]]
>
> My guess is that for most outlines, the difference would amount to a few
> milliseconds, at most.
>
> Do have any data to show that this method is a problem?
Nope, profiling is most useful when trying to find slow areas of the
code. This kind of "obviously correct" optimization is just something
you casually do here and there when you see inefficient code.