Skip to content

Commit

Permalink
Correctly enqueue data in moveToTail
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhinkin committed Jun 4, 2024
1 parent e9cc737 commit c923ad2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/common/src/unsafe/UnsafeBufferOperations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public object UnsafeBufferOperations {
val tail = buffer.tail
if (tail == null) {
buffer.head = segment
buffer.tail = tail
buffer.tail = segment
} else {
buffer.tail = tail.push(segment)
}
Expand Down
12 changes: 12 additions & 0 deletions core/common/test/unsafe/UnsafeBufferOperationsMoveTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,16 @@ class UnsafeBufferOperationsMoveTest {
UnsafeBufferOperations.moveToTail(Buffer(), ByteArray(10), 11, 12)
}
}

@Test
fun moveMultipleSegments() {
val buffer = Buffer()
val segmentsCount = 10
for (i in 0 ..< segmentsCount) {
UnsafeBufferOperations.moveToTail(buffer, byteArrayOf(i.toByte()))
}
assertEquals(10, buffer.size)
assertEquals(listOf(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), segmentSizes(buffer))
assertContentEquals(ByteArray(segmentsCount) { it.toByte() }, buffer.readByteArray())
}
}

0 comments on commit c923ad2

Please sign in to comment.