Skip to content

Commit 0483f2c

Browse files
committed
Introduce addElementAt function that takes nullable MutabilityOwnership
It replaces addElementAt and mutableAddElementAt
1 parent dd791a1 commit 0483f2c

File tree

1 file changed

+3
-12
lines changed
  • core/commonMain/src/implementations/immutableSet

1 file changed

+3
-12
lines changed

core/commonMain/src/implementations/immutableSet/TrieNode.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,7 @@ internal class TrieNode<E>(
9595
return buffer[index] as TrieNode<E>
9696
}
9797

98-
private fun addElementAt(positionMask: Int, element: E): TrieNode<E> {
99-
// assert(hasNoCellAt(positionMask))
100-
101-
val index = indexOfCellAt(positionMask)
102-
val newBitmap = bitmap or positionMask
103-
val newBuffer = buffer.addElementAtIndex(index, element)
104-
return setProperties(newBitmap, newBuffer, owner = null)
105-
}
106-
107-
private fun mutableAddElementAt(positionMask: Int, element: E, owner: MutabilityOwnership): TrieNode<E> {
98+
private fun addElementAt(positionMask: Int, element: E, owner: MutabilityOwnership?): TrieNode<E> {
10899
// assert(hasNoCellAt(positionMask))
109100

110101
val index = indexOfCellAt(positionMask)
@@ -708,7 +699,7 @@ internal class TrieNode<E>(
708699
val cellPositionMask = 1 shl indexSegment(elementHash, shift)
709700

710701
if (hasNoCellAt(cellPositionMask)) { // element is absent
711-
return addElementAt(cellPositionMask, element)
702+
return addElementAt(cellPositionMask, element, owner = null)
712703
}
713704

714705
val cellIndex = indexOfCellAt(cellPositionMask)
@@ -732,7 +723,7 @@ internal class TrieNode<E>(
732723

733724
if (hasNoCellAt(cellPosition)) { // element is absent
734725
mutator.size++
735-
return mutableAddElementAt(cellPosition, element, mutator.ownership)
726+
return addElementAt(cellPosition, element, mutator.ownership)
736727
}
737728

738729
val cellIndex = indexOfCellAt(cellPosition)

0 commit comments

Comments
 (0)