Merge pull request '1.3.3 release' (#8) from develop into main
All checks were successful
/ publish (push) Successful in 1m22s

Reviewed-on: Infendro/bytes-kt#8
This commit was merged in pull request #8.
This commit is contained in:
2026-01-22 10:59:48 +00:00
committed by Gitea
5 changed files with 110 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ jobs:
uses: actions/cache@v4
with:
key: gradle-${{ hashFiles('**/libs.versions.toml') }}
restore-keys: gradle-
restore-keys: gradle
path: |
~/.gradle/caches/
~/.gradle/wrapper/
@@ -28,7 +28,7 @@ jobs:
uses: actions/cache@v4
with:
key: konan-${{ hashFiles('**/libs.versions.toml') }}
restore-keys: konan-
restore-keys: konan
path: |
~/.konan/
@@ -36,7 +36,7 @@ jobs:
uses: actions/cache@v4
with:
key: node-${{ hashFiles('**/libs.versions.toml') }}
restore-keys: node-
restore-keys: node
path: |
~/.gradle/nodejs
~/.gradle/yarn

View File

@@ -12,6 +12,6 @@ repositories {
}
commonMain.dependencies {
implementation("com.infendro:bytes:1.3.2")
implementation("com.infendro:bytes:1.3.3")
}
```

View File

@@ -5,7 +5,7 @@ import com.infendro.plugin.token
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
group = "com.infendro"
version = "1.3.2"
version = "1.3.3"
plugins {
alias(libs.plugins.infendro)

View File

@@ -25,15 +25,33 @@ private inline fun ByteArray.combineInto(
}
}
private inline fun ByteArray.combine(
that: ByteArray,
private inline fun ByteArray.combineInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
combine: (Byte, Byte) -> Byte,
): ByteArray {
) {
val length = endIndex - startIndex
require(length >= 0)
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - length))
repeat(length) { i ->
destination[destinationOffset + i] = combine(this[startIndex + i], that)
}
}
private inline fun ByteArray.combine(that: ByteArray, combine: (Byte, Byte) -> Byte): ByteArray {
require(this.size == that.size)
return ByteArray(size).also { combineInto(that, it, combine = combine) }
}
private inline fun ByteArray.combine(that: Byte, combine: (Byte, Byte) -> Byte): ByteArray =
ByteArray(size).also { combineInto(that, it, combine = combine) }
fun ByteArray.invInto(
destination: ByteArray,
destinationOffset: Int = 0,
@@ -62,9 +80,20 @@ fun ByteArray.andInto(
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a and b }
fun ByteArray.andInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a and b }
infix fun ByteArray.and(that: ByteArray): ByteArray =
combine(that) { a, b -> a and b }
infix fun ByteArray.and(that: Byte): ByteArray =
combine(that) { a, b -> a and b }
fun ByteArray.orInto(
that: ByteArray,
destination: ByteArray,
@@ -74,9 +103,20 @@ fun ByteArray.orInto(
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a or b }
fun ByteArray.orInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a or b }
infix fun ByteArray.or(that: ByteArray): ByteArray =
combine(that) { a, b -> a or b }
infix fun ByteArray.or(that: Byte): ByteArray =
combine(that) { a, b -> a or b }
fun ByteArray.xorInto(
that: ByteArray,
destination: ByteArray,
@@ -86,5 +126,16 @@ fun ByteArray.xorInto(
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a xor b }
fun ByteArray.xorInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a xor b }
infix fun ByteArray.xor(that: ByteArray): ByteArray =
combine(that) { a, b -> a xor b }
infix fun ByteArray.xor(that: Byte): ByteArray =
combine(that) { a, b -> a xor b }

View File

@@ -31,9 +31,26 @@ fun UByteArray.andInto(
thatStartIndex,
)
fun UByteArray.andInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().andInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
)
infix fun UByteArray.and(that: UByteArray): UByteArray =
UByteArray(size).also { andInto(that, it) }
infix fun UByteArray.and(that: UByte): UByteArray =
UByteArray(size).also { andInto(that, it) }
fun UByteArray.orInto(
that: UByteArray,
destination: UByteArray,
@@ -50,9 +67,26 @@ fun UByteArray.orInto(
thatStartIndex,
)
fun UByteArray.orInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().orInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
)
infix fun UByteArray.or(that: UByteArray): UByteArray =
UByteArray(size).also { orInto(that, it) }
infix fun UByteArray.or(that: UByte): UByteArray =
UByteArray(size).also { orInto(that, it) }
fun UByteArray.xorInto(
that: UByteArray,
destination: UByteArray,
@@ -69,5 +103,22 @@ fun UByteArray.xorInto(
thatStartIndex,
)
fun UByteArray.xorInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().xorInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
)
infix fun UByteArray.xor(that: UByteArray): UByteArray =
UByteArray(size).also { xorInto(that, it) }
infix fun UByteArray.xor(that: UByte): UByteArray =
UByteArray(size).also { xorInto(that, it) }