@@ -153,21 +153,9 @@ internal class TrieNode<E>(
153
153
}
154
154
155
155
private fun moveElementToNode (elementIndex : Int , newElementHash : Int , newElement : E ,
156
- shift : Int ): TrieNode <E > {
157
- val newBuffer = buffer.copyOf()
158
- newBuffer[elementIndex] = makeNodeAtIndex(elementIndex, newElementHash, newElement, shift, null )
159
- return TrieNode (bitmap, newBuffer)
160
- }
161
-
162
- private fun mutableMoveElementToNode (elementIndex : Int , newElementHash : Int , newElement : E ,
163
- shift : Int , owner : MutabilityOwnership ): TrieNode <E > {
164
- if (ownedBy == = owner) {
165
- buffer[elementIndex] = makeNodeAtIndex(elementIndex, newElementHash, newElement, shift, owner)
166
- return this
167
- }
168
- val newBuffer = buffer.copyOf()
169
- newBuffer[elementIndex] = makeNodeAtIndex(elementIndex, newElementHash, newElement, shift, owner)
170
- return TrieNode (bitmap, newBuffer, owner)
156
+ shift : Int , owner : MutabilityOwnership ? ): TrieNode <E > {
157
+ val node = makeNodeAtIndex(elementIndex, newElementHash, newElement, shift, owner)
158
+ return setCellAtIndex(elementIndex, node, owner)
171
159
}
172
160
173
161
private fun makeNode (elementHash1 : Int , element1 : E , elementHash2 : Int , element2 : E ,
@@ -746,7 +734,7 @@ internal class TrieNode<E>(
746
734
}
747
735
// element is directly in buffer
748
736
if (element == buffer[cellIndex]) return this
749
- return moveElementToNode(cellIndex, elementHash, element, shift)
737
+ return moveElementToNode(cellIndex, elementHash, element, shift, owner = null )
750
738
}
751
739
752
740
fun mutableAdd (elementHash : Int , element : E , shift : Int , mutator : PersistentHashSetBuilder <* >): TrieNode <E > {
@@ -771,7 +759,7 @@ internal class TrieNode<E>(
771
759
// element is directly in buffer
772
760
if (element == buffer[cellIndex]) return this
773
761
mutator.size++
774
- return mutableMoveElementToNode (cellIndex, elementHash, element, shift, mutator.ownership)
762
+ return moveElementToNode (cellIndex, elementHash, element, shift, mutator.ownership)
775
763
}
776
764
777
765
fun remove (elementHash : Int , element : E , shift : Int ): TrieNode <E > {
0 commit comments