Skip to content

Commit c923ad2

Browse files
committed
Correctly enqueue data in moveToTail
1 parent e9cc737 commit c923ad2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

core/common/src/unsafe/UnsafeBufferOperations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public object UnsafeBufferOperations {
4343
val tail = buffer.tail
4444
if (tail == null) {
4545
buffer.head = segment
46-
buffer.tail = tail
46+
buffer.tail = segment
4747
} else {
4848
buffer.tail = tail.push(segment)
4949
}

core/common/test/unsafe/UnsafeBufferOperationsMoveTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,16 @@ class UnsafeBufferOperationsMoveTest {
7676
UnsafeBufferOperations.moveToTail(Buffer(), ByteArray(10), 11, 12)
7777
}
7878
}
79+
80+
@Test
81+
fun moveMultipleSegments() {
82+
val buffer = Buffer()
83+
val segmentsCount = 10
84+
for (i in 0 ..< segmentsCount) {
85+
UnsafeBufferOperations.moveToTail(buffer, byteArrayOf(i.toByte()))
86+
}
87+
assertEquals(10, buffer.size)
88+
assertEquals(listOf(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), segmentSizes(buffer))
89+
assertContentEquals(ByteArray(segmentsCount) { it.toByte() }, buffer.readByteArray())
90+
}
7991
}

0 commit comments

Comments
 (0)