Skip to content

Commit

Permalink
Copy nodes when changing the nature of the leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Mar 11, 2021
1 parent cea9b8c commit f4d7656
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private NodeImpl addMethodNode(String name, Class<?>[] parameterTypes) {
}

public NodeImpl makeLeafNodeIterable() {
requiresWriteableNodeList();
copyNodeList();

currentLeafNode = NodeImpl.makeIterable( currentLeafNode );

Expand All @@ -205,7 +205,7 @@ public NodeImpl makeLeafNodeIterable() {
}

public NodeImpl makeLeafNodeIterableAndSetIndex(Integer index) {
requiresWriteableNodeList();
copyNodeList();

currentLeafNode = NodeImpl.makeIterableAndSetIndex( currentLeafNode, index );

Expand All @@ -215,7 +215,7 @@ public NodeImpl makeLeafNodeIterableAndSetIndex(Integer index) {
}

public NodeImpl makeLeafNodeIterableAndSetMapKey(Object key) {
requiresWriteableNodeList();
copyNodeList();

currentLeafNode = NodeImpl.makeIterableAndSetMapKey( currentLeafNode, key );

Expand Down Expand Up @@ -300,6 +300,10 @@ private void requiresWriteableNodeList() {
return;
}

copyNodeList();
}

private void copyNodeList() {
// Usually, the write operation is about adding one more node, so let's make the list one element larger.
List<Node> newNodeList = new ArrayList<>( nodeList.size() + 1 );
newNodeList.addAll( nodeList );
Expand Down

0 comments on commit f4d7656

Please sign in to comment.