Change implementations of contentEquals and minOf/maxOf for Native

To conform to the behavior in other platforms.
This commit is contained in:
Ilya Gorbunov
2018-12-27 04:50:10 +03:00
committed by Pavel Punegov
parent 53838e39c8
commit ea943b715c
2 changed files with 31 additions and 97 deletions
@@ -180,16 +180,10 @@ public actual fun <T> Array<out T>.contentDeepToString(): String {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean { public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -200,16 +194,10 @@ public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boo
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -220,16 +208,10 @@ public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -240,16 +222,10 @@ public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -260,16 +236,10 @@ public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -280,16 +250,10 @@ public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (!this[i].equals(other[i])) return false
return false
}
} }
return true return true
} }
@@ -300,16 +264,10 @@ public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (!this[i].equals(other[i])) return false
return false
}
} }
return true return true
} }
@@ -320,16 +278,10 @@ public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean { public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -340,16 +292,10 @@ public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
public actual infix fun CharArray.contentEquals(other: CharArray): Boolean { public actual infix fun CharArray.contentEquals(other: CharArray): Boolean {
if (this === other) { if (this === other) return true
return true if (size != other.size) return false
}
if (size != other.size) {
return false
}
for (i in indices) { for (i in indices) {
if (this[i] != other[i]) { if (this[i] != other[i]) return false
return false
}
} }
return true return true
} }
@@ -62,12 +62,7 @@ public actual inline fun maxOf(a: Long, b: Long): Long {
@SinceKotlin("1.1") @SinceKotlin("1.1")
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public actual inline fun maxOf(a: Float, b: Float): Float { public actual inline fun maxOf(a: Float, b: Float): Float {
// TODO: Check +/-0.0 return if (a.compareTo(b) >= 0) a else b
return when {
a.isNaN() -> a
b.isNaN() -> b
else -> if (a >= b) a else b
}
} }
/** /**
@@ -76,12 +71,7 @@ public actual inline fun maxOf(a: Float, b: Float): Float {
@SinceKotlin("1.1") @SinceKotlin("1.1")
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public actual inline fun maxOf(a: Double, b: Double): Double { public actual inline fun maxOf(a: Double, b: Double): Double {
// TODO: Check +/-0.0 return if (a.compareTo(b) >= 0) a else b
return when {
a.isNaN() -> a
b.isNaN() -> b
else -> if (a >= b) a else b
}
} }
/** /**
@@ -197,11 +187,10 @@ public actual inline fun minOf(a: Long, b: Long): Long {
@SinceKotlin("1.1") @SinceKotlin("1.1")
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public actual inline fun minOf(a: Float, b: Float): Float { public actual inline fun minOf(a: Float, b: Float): Float {
// TODO: Check +/-0.0
return when { return when {
a.isNaN() -> a a.isNaN() -> a
b.isNaN() -> b b.isNaN() -> b
else -> if (a <= b) a else b else -> if (a.compareTo(b) <= 0) a else b
} }
} }
@@ -211,11 +200,10 @@ public actual inline fun minOf(a: Float, b: Float): Float {
@SinceKotlin("1.1") @SinceKotlin("1.1")
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public actual inline fun minOf(a: Double, b: Double): Double { public actual inline fun minOf(a: Double, b: Double): Double {
// TODO: Check +/-0.0
return when { return when {
a.isNaN() -> a a.isNaN() -> a
b.isNaN() -> b b.isNaN() -> b
else -> if (a <= b) a else b else -> if (a.compareTo(b) <= 0) a else b
} }
} }