From 947ef907a5a0b166382e7133b71cfe90a31f6bbd Mon Sep 17 00:00:00 2001 From: Infendro Date: Wed, 14 Jan 2026 16:03:16 +0100 Subject: [PATCH] more optimizations, split ci --- .gitea/workflows/ci.yaml | 92 ------------------- .gitea/workflows/publish.yaml | 47 ++++++++++ .gitea/workflows/test.yaml | 45 +++++++++ .../com/infendro/bytes/ubytearray/Copy.kt | 32 ++++--- .../kotlin/com/infendro/bytes/uint/Copy.kt | 23 ++++- .../kotlin/com/infendro/bytes/ulong/Copy.kt | 31 ++++++- 6 files changed, 160 insertions(+), 110 deletions(-) delete mode 100644 .gitea/workflows/ci.yaml create mode 100644 .gitea/workflows/publish.yaml create mode 100644 .gitea/workflows/test.yaml diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml deleted file mode 100644 index 2f46684..0000000 --- a/.gitea/workflows/ci.yaml +++ /dev/null @@ -1,92 +0,0 @@ -on: - push: - branches: [ develop, main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: linux - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Java - uses: actions/setup-java@v4 - with: - java-version: '24' - distribution: 'temurin' - - - name: Cache Gradle - uses: actions/cache@v4 - with: - key: gradle-${{ hashFiles('**/libs.versions.toml') }} - restore-keys: gradle- - path: | - ~/.gradle/caches/ - ~/.gradle/wrapper/ - - - name: Cache Konan - uses: actions/cache@v4 - with: - key: konan-${{ hashFiles('**/libs.versions.toml') }} - restore-keys: konan- - path: | - ~/.konan/ - - - name: Cache Node - uses: actions/cache@v4 - with: - key: node-${{ hashFiles('**/libs.versions.toml') }} - restore-keys: node- - path: | - ~/.gradle/nodejs - ~/.gradle/yarn - - - name: Test - run: ./gradlew allTests - - publish: - if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} - needs: test - runs-on: linux - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Java - uses: actions/setup-java@v4 - with: - java-version: '24' - distribution: 'temurin' - - - name: Cache Gradle - uses: actions/cache@v4 - with: - key: gradle-${{ hashFiles('**/libs.versions.toml') }} - restore-keys: gradle- - path: | - ~/.gradle/caches/ - ~/.gradle/wrapper/ - - - name: Cache Konan - uses: actions/cache@v4 - with: - key: konan-${{ hashFiles('**/libs.versions.toml') }} - restore-keys: konan- - path: | - ~/.konan/ - - - name: Cache Node - uses: actions/cache@v4 - with: - key: node-${{ hashFiles('**/libs.versions.toml') }} - restore-keys: node- - path: | - ~/.gradle/nodejs - ~/.gradle/yarn - - - name: Publish - run: ./gradlew publish - env: - INFENDRO__TOKEN: ${{ secrets.TOKEN }} diff --git a/.gitea/workflows/publish.yaml b/.gitea/workflows/publish.yaml new file mode 100644 index 0000000..3e3641d --- /dev/null +++ b/.gitea/workflows/publish.yaml @@ -0,0 +1,47 @@ +on: + push: + branches: [ main ] + +jobs: + publish: + runs-on: linux + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + java-version: '24' + distribution: 'temurin' + + - name: Cache Gradle + uses: actions/cache@v4 + with: + key: gradle-${{ hashFiles('**/libs.versions.toml') }} + restore-keys: gradle- + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + + - name: Cache Konan + uses: actions/cache@v4 + with: + key: konan-${{ hashFiles('**/libs.versions.toml') }} + restore-keys: konan- + path: | + ~/.konan/ + + - name: Cache Node + uses: actions/cache@v4 + with: + key: node-${{ hashFiles('**/libs.versions.toml') }} + restore-keys: node- + path: | + ~/.gradle/nodejs + ~/.gradle/yarn + + - name: Publish + run: ./gradlew publish + env: + INFENDRO__TOKEN: ${{ secrets.TOKEN }} diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml new file mode 100644 index 0000000..39e3aad --- /dev/null +++ b/.gitea/workflows/test.yaml @@ -0,0 +1,45 @@ +on: + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: linux + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + java-version: '24' + distribution: 'temurin' + + - name: Cache Gradle + uses: actions/cache@v4 + with: + key: gradle-${{ hashFiles('**/libs.versions.toml') }} + restore-keys: gradle- + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + + - name: Cache Konan + uses: actions/cache@v4 + with: + key: konan-${{ hashFiles('**/libs.versions.toml') }} + restore-keys: konan- + path: | + ~/.konan/ + + - name: Cache Node + uses: actions/cache@v4 + with: + key: node-${{ hashFiles('**/libs.versions.toml') }} + restore-keys: node- + path: | + ~/.gradle/nodejs + ~/.gradle/yarn + + - name: Test + run: ./gradlew allTests diff --git a/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Copy.kt b/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Copy.kt index 8fcda61..98f5d30 100644 --- a/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Copy.kt +++ b/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Copy.kt @@ -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) } } } diff --git a/src/commonMain/kotlin/com/infendro/bytes/uint/Copy.kt b/src/commonMain/kotlin/com/infendro/bytes/uint/Copy.kt index fd85bcb..1a45224 100644 --- a/src/commonMain/kotlin/com/infendro/bytes/uint/Copy.kt +++ b/src/commonMain/kotlin/com/infendro/bytes/uint/Copy.kt @@ -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() + } + } } } diff --git a/src/commonMain/kotlin/com/infendro/bytes/ulong/Copy.kt b/src/commonMain/kotlin/com/infendro/bytes/ulong/Copy.kt index 8d1914a..7152346 100644 --- a/src/commonMain/kotlin/com/infendro/bytes/ulong/Copy.kt +++ b/src/commonMain/kotlin/com/infendro/bytes/ulong/Copy.kt @@ -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() + } + } } }