@@ -117,7 +117,7 @@ internal class TrieNode<E>(
117
117
}
118
118
119
119
/* * The given [newNode] must not be a part of any persistent set instance. */
120
- private fun updateNodeAtIndex (nodeIndex : Int , newNode : TrieNode <E >): TrieNode <E > {
120
+ private fun canonicalizeNodeAtIndex (nodeIndex : Int , newNode : TrieNode <E >, owner : MutabilityOwnership ? ): TrieNode <E > {
121
121
// assert(buffer[nodeIndex] !== newNode)
122
122
val cell: Any?
123
123
@@ -132,24 +132,6 @@ internal class TrieNode<E>(
132
132
cell = newNode
133
133
}
134
134
135
- return setCellAtIndex(nodeIndex, cell, owner = null )
136
- }
137
-
138
- /* * The given [newNode] must not be a part of any persistent set instance. */
139
- private fun mutableUpdateNodeAtIndex (nodeIndex : Int , newNode : TrieNode <E >, owner : MutabilityOwnership ): TrieNode <E > {
140
- val cell: Any?
141
-
142
- val newNodeBuffer = newNode.buffer
143
- if (newNodeBuffer.size == 1 && newNodeBuffer[0 ] !is TrieNode <* >) {
144
- if (buffer.size == 1 ) {
145
- newNode.bitmap = bitmap
146
- return newNode
147
- }
148
- cell = newNodeBuffer[0 ]
149
- } else {
150
- cell = newNode
151
- }
152
-
153
135
return setCellAtIndex(nodeIndex, cell, owner)
154
136
}
155
137
@@ -808,7 +790,7 @@ internal class TrieNode<E>(
808
790
targetNode.remove(elementHash, element, shift + LOG_MAX_BRANCHING_FACTOR )
809
791
}
810
792
if (targetNode == = newNode) return this
811
- return updateNodeAtIndex (cellIndex, newNode)
793
+ return canonicalizeNodeAtIndex (cellIndex, newNode, owner = null )
812
794
}
813
795
// element is directly in buffer
814
796
if (element == buffer[cellIndex]) {
@@ -836,10 +818,8 @@ internal class TrieNode<E>(
836
818
// Otherwise the single element would have been lifted up.
837
819
// If targetNode is owned by mutator, this node is also owned by mutator. Thus no new node will be created to replace this node.
838
820
// If newNode !== targetNode, it is newly created.
839
- if (targetNode.ownedBy == = mutator.ownership || targetNode != = newNode) {
840
- return mutableUpdateNodeAtIndex(cellIndex, newNode, mutator.ownership)
841
- }
842
- return this
821
+ if (targetNode.ownedBy != = mutator.ownership && targetNode == = newNode) return this
822
+ return canonicalizeNodeAtIndex(cellIndex, newNode, mutator.ownership)
843
823
}
844
824
// element is directly in buffer
845
825
if (element == buffer[cellIndex]) {
0 commit comments