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 + Temporarily circumvent JS-IR performance issue with m…
Browse files Browse the repository at this point in the history
…in/max
  • Loading branch information
soywiz committed Feb 4, 2021
1 parent dfac677 commit d55e118
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 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.klock
Expand Down
4 changes: 2 additions & 2 deletions klock/src/commonMain/kotlin/com/soywiz/klock/DateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ inline class DateTime(
override fun toString(): String = DateFormat.DEFAULT_FORMAT.format(this)
}

fun max(a: DateTime, b: DateTime): DateTime = DateTime.fromUnix(max(a.unixMillis, b.unixMillis))
fun min(a: DateTime, b: DateTime): DateTime = DateTime.fromUnix(min(a.unixMillis, b.unixMillis))
fun max(a: DateTime, b: DateTime): DateTime = DateTime.fromUnix(max2(a.unixMillis, b.unixMillis))
fun min(a: DateTime, b: DateTime): DateTime = DateTime.fromUnix(min2(a.unixMillis, b.unixMillis))
fun DateTime.clamp(min: DateTime, max: DateTime): DateTime = when {
this < min -> min
this > max -> max
Expand Down
4 changes: 2 additions & 2 deletions klock/src/commonMain/kotlin/com/soywiz/klock/TimeSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ inline class TimeSpan(
fun TimeSpan.toTimeString(components: Int = 3, addMilliseconds: Boolean = false): String =
TimeSpan.toTimeString(milliseconds, components, addMilliseconds)

fun max(a: TimeSpan, b: TimeSpan): TimeSpan = max(a.milliseconds, b.milliseconds).milliseconds
fun min(a: TimeSpan, b: TimeSpan): TimeSpan = min(a.milliseconds, b.milliseconds).milliseconds
fun max(a: TimeSpan, b: TimeSpan): TimeSpan = max2(a.milliseconds, b.milliseconds).milliseconds
fun min(a: TimeSpan, b: TimeSpan): TimeSpan = min2(a.milliseconds, b.milliseconds).milliseconds
fun TimeSpan.clamp(min: TimeSpan, max: TimeSpan): TimeSpan = when {
this < min -> min
this > max -> max
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ internal class Moduler(val value: Double) {
}

internal infix fun Double.intDiv(other: Double) = floor(this / other)

@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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.soywiz.klock

import com.soywiz.klock.internal.*
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random
Expand Down Expand Up @@ -33,7 +34,7 @@ class DateTimeRangeSetTest {
fun randomRange(): DateTimeRange {
val a = random.nextInt(min, max)
val b = random.nextInt(min, max)
return range(min(a, b), max(a, b))
return range(min2(a, b), max2(a, b))
}
return (0 until count).map { randomRange() }
}
Expand Down

0 comments on commit d55e118

Please sign in to comment.