more optimizations, split ci
All checks were successful
/ test (pull_request) Successful in 6m14s

This commit is contained in:
2026-01-14 16:03:16 +01:00
parent 23b565ca0a
commit 947ef907a5
6 changed files with 160 additions and 110 deletions

View File

@@ -19,16 +19,18 @@ fun UByteArray.copyInto(
when (order) {
BIG_ENDIAN -> {
repeat(length / 4) { i ->
val offset = startIndex + (i * 4)
destination[destinationOffset + i] =
(this[startIndex].toUInt() shl 24) or (this[startIndex + 1].toUInt() shl 16) or
(this[startIndex + 2].toUInt() shl 8) or this[startIndex + 3].toUInt()
(this[offset].toUInt() shl 24) or (this[offset + 1].toUInt() shl 16) or
(this[offset + 2].toUInt() shl 8) or this[offset + 3].toUInt()
}
}
LITTLE_ENDIAN -> {
repeat(length / 4) { i ->
val offset = startIndex + (i * 4)
destination[destinationOffset + i] =
this[startIndex].toUInt() or (this[startIndex + 1].toUInt() shl 8) or
(this[startIndex + 2].toUInt() shl 16) or (this[startIndex + 3].toUInt() shl 24)
this[offset].toUInt() or (this[offset + 1].toUInt() shl 8) or
(this[offset + 2].toUInt() shl 16) or (this[offset + 3].toUInt() shl 24)
}
}
}
@@ -56,21 +58,23 @@ fun UByteArray.copyInto(
when (order) {
BIG_ENDIAN -> {
repeat(length / 4) { i ->
repeat(length / 8) { i ->
val offset = startIndex + (i * 8)
destination[destinationOffset + i] =
(this[startIndex].toULong() shl 56) or (this[startIndex + 1].toULong() shl 48) or
(this[startIndex + 2].toULong() shl 40) or (this[startIndex + 3].toULong() shl 32) or
(this[startIndex + 4].toULong() shl 24) or (this[startIndex + 5].toULong() shl 16) or
(this[startIndex + 6].toULong() shl 8) or this[startIndex + 7].toULong()
(this[offset].toULong() shl 56) or (this[offset + 1].toULong() shl 48) or
(this[offset + 2].toULong() shl 40) or (this[offset + 3].toULong() shl 32) or
(this[offset + 4].toULong() shl 24) or (this[offset + 5].toULong() shl 16) or
(this[offset + 6].toULong() shl 8) or this[offset + 7].toULong()
}
}
LITTLE_ENDIAN -> {
repeat(length / 4) { i ->
repeat(length / 8) { i ->
val offset = startIndex + (i * 8)
destination[destinationOffset + i] =
this[startIndex].toULong() or (this[startIndex + 1].toULong() shl 8) or
(this[startIndex + 2].toULong() shl 16) or (this[startIndex + 3].toULong() shl 24) or
(this[startIndex + 4].toULong() shl 32) or (this[startIndex + 5].toULong() shl 40) or
(this[startIndex + 6].toULong() shl 48) or (this[startIndex + 7].toULong() shl 56)
this[offset].toULong() or (this[offset + 1].toULong() shl 8) or
(this[offset + 2].toULong() shl 16) or (this[offset + 3].toULong() shl 24) or
(this[offset + 4].toULong() shl 32) or (this[offset + 5].toULong() shl 40) or
(this[offset + 6].toULong() shl 48) or (this[offset + 7].toULong() shl 56)
}
}
}

View File

@@ -45,8 +45,27 @@ fun UIntArray.copyInto(
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - (length * 4)))
repeat(length) { i ->
this[startIndex + i].copyInto(destination, destinationOffset + (i * 4), order)
when (order) {
BIG_ENDIAN -> {
repeat(length) { i ->
val offset = destinationOffset + (i * 4)
val value = this[startIndex + i]
destination[offset] = (value shr 24).toUByte()
destination[offset + 1] = (value shr 16).toUByte()
destination[offset + 2] = (value shr 8).toUByte()
destination[offset + 3] = value.toUByte()
}
}
LITTLE_ENDIAN -> {
repeat(length) { i ->
val offset = destinationOffset + (i * 4)
val value = this[startIndex + i]
destination[offset] = value.toUByte()
destination[offset + 1] = (value shr 8).toUByte()
destination[offset + 2] = (value shr 16).toUByte()
destination[offset + 3] = (value shr 24).toUByte()
}
}
}
}

View File

@@ -53,8 +53,35 @@ fun ULongArray.copyInto(
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - (length * 8)))
repeat(length) { i ->
this[startIndex + i].copyInto(destination, destinationOffset + (i * 8), order)
when (order) {
BIG_ENDIAN -> {
repeat(length) { i ->
val offset = destinationOffset + (i * 8)
val value = this[startIndex + i]
destination[offset] = (value shr 56).toUByte()
destination[offset + 1] = (value shr 48).toUByte()
destination[offset + 2] = (value shr 40).toUByte()
destination[offset + 3] = (value shr 32).toUByte()
destination[offset + 4] = (value shr 24).toUByte()
destination[offset + 5] = (value shr 16).toUByte()
destination[offset + 6] = (value shr 8).toUByte()
destination[offset + 7] = value.toUByte()
}
}
LITTLE_ENDIAN -> {
repeat(length) { i ->
val offset = destinationOffset + (i * 8)
val value = this[startIndex + i]
destination[offset] = value.toUByte()
destination[offset + 1] = (value shr 8).toUByte()
destination[offset + 2] = (value shr 16).toUByte()
destination[offset + 3] = (value shr 24).toUByte()
destination[offset + 4] = (value shr 32).toUByte()
destination[offset + 5] = (value shr 40).toUByte()
destination[offset + 6] = (value shr 48).toUByte()
destination[offset + 7] = (value shr 56).toUByte()
}
}
}
}