Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Kotlin 1.4.30 + Circumvent min/max performance issue on JS-IR
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Feb 4, 2021
1 parent 96b9b3d commit 430a9c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# sytleguide
kotlin.code.style=official

# Kotlin 1.4.30-RC: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
easyPluginVersion=0.12.5
# Kotlin 1.4.30: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
easyPluginVersion=0.13.0

# version
group=com.soywiz.korlibs.krypto
Expand Down
4 changes: 3 additions & 1 deletion krypto/src/commonMain/kotlin/com/soywiz/krypto/Hasher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.soywiz.krypto

import com.soywiz.krypto.encoding.Base64
import com.soywiz.krypto.encoding.Hex
import com.soywiz.krypto.internal.*
import com.soywiz.krypto.internal.arraycopy
import com.soywiz.krypto.internal.min2
import kotlin.math.min

open class HasherFactory(val create: () -> Hasher) {
Expand Down Expand Up @@ -35,7 +37,7 @@ abstract class Hasher(val chunkSize: Int, val digestSize: Int) {
var left = count
while (left > 0) {
val remainingInChunk = chunkSize - writtenInChunk
val toRead = min(remainingInChunk, left)
val toRead = min2(remainingInChunk, left)
arraycopy(data, curr, chunk, writtenInChunk, toRead)
left -= toRead
curr += toRead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ internal fun arraycopy(src: IntArray, srcPos: Int, dst: IntArray, dstPos: Int, c
internal fun ByteArray.readU8(o: Int): Int = this[o].toInt() and 0xFF
internal fun ByteArray.readS32_be(o: Int): Int =
(readU8(o + 3) shl 0) or (readU8(o + 2) shl 8) or (readU8(o + 1) shl 16) or (readU8(o + 0) shl 24)

@PublishedApi internal fun min2(a: Int, b: Int) = if (a < b) a else b
@PublishedApi internal fun max2(a: Int, b: Int) = if (a > b) a else b

@PublishedApi internal fun min2(a: Float, b: Float) = if (a < b) a else b
@PublishedApi internal fun max2(a: Float, b: Float) = if (a > b) a else b

@PublishedApi internal fun min2(a: Double, b: Double) = if (a < b) a else b
@PublishedApi internal fun max2(a: Double, b: Double) = if (a > b) a else b

0 comments on commit 430a9c3

Please sign in to comment.