Skip to content

Commit 1ceb2df

Browse files
committed
minor improvement & bugfix
1 parent d958e9c commit 1ceb2df

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎solid/extensions/child_optimizer.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __next__(self):
3636
return d
3737

3838
def childOptimizer(root):
39+
import copy
40+
root = copy.deepcopy(root)
3941
depthMap = DepthMap()
4042
nodeReferenceCount = {}
4143
nodeParents = {}
@@ -66,13 +68,11 @@ def collectData(node, parent=None, depth=0):
6668
collectData(root)
6769

6870
#extract the nodes we want to extract as children
69-
childsToExtract = [n for n in nodeReferenceCount.keys() if nodeReferenceCount[n] > 1]
71+
childsToExtract = [n for n in depthMap if nodeReferenceCount[n] > 1]
7072
getChildId = lambda n : len(childsToExtract) - childsToExtract.index(n) - 1
7173

7274
#replace the reference to the objects with calls to children(id)
73-
for n in depthMap:
74-
if not n in childsToExtract:
75-
continue
75+
for n in childsToExtract:
7676
parents = nodeParents[n]
7777
#replace the references in each parent
7878
for p in parents:

0 commit comments

Comments
 (0)