Specialize contentDeepEquals/HashCode/ToString for arrays of unsigned types
#KT-26388
This commit is contained in:
@@ -295,9 +295,13 @@ public fun CharArray.binarySearch(element: Char, fromIndex: Int = 0, toIndex: In
|
||||
* If any of arrays contains itself on any nesting level the behavior is undefined.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@JvmName("contentDeepEqualsInline")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean {
|
||||
return java.util.Arrays.deepEquals(this, other)
|
||||
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
|
||||
return contentDeepEqualsImpl(other)
|
||||
else
|
||||
return java.util.Arrays.deepEquals(this, other)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,9 +311,13 @@ public actual inline infix fun <T> Array<out T>.contentDeepEquals(other: Array<o
|
||||
* If any of arrays contains itself on any nesting level the behavior is undefined.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@JvmName("contentDeepHashCodeInline")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun <T> Array<out T>.contentDeepHashCode(): Int {
|
||||
return java.util.Arrays.deepHashCode(this)
|
||||
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
|
||||
return contentDeepHashCodeImpl()
|
||||
else
|
||||
return java.util.Arrays.deepHashCode(this)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,9 +330,13 @@ public actual inline fun <T> Array<out T>.contentDeepHashCode(): Int {
|
||||
* @sample samples.collections.Arrays.ContentOperations.contentDeepToString
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@JvmName("contentDeepToStringInline")
|
||||
@kotlin.internal.InlineOnly
|
||||
public actual inline fun <T> Array<out T>.contentDeepToString(): String {
|
||||
return java.util.Arrays.deepToString(this)
|
||||
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
|
||||
return contentDeepToStringImpl()
|
||||
else
|
||||
return java.util.Arrays.deepToString(this)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,4 +47,14 @@ internal actual fun <T> arrayOfNulls(reference: Array<T>, size: Int): Array<T> {
|
||||
@SinceKotlin("1.3")
|
||||
internal fun copyOfRangeToIndexCheck(toIndex: Int, size: Int) {
|
||||
if (toIndex > size) throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@PublishedApi
|
||||
@kotlin.jvm.JvmName("contentDeepHashCode")
|
||||
internal fun <T> Array<out T>.contentDeepHashCodeImpl(): Int =
|
||||
// returns valid result for unsigned arrays by accident:
|
||||
// hash code of an inline class, which an unsigned array is,
|
||||
// is calculated structurally as in a data class
|
||||
java.util.Arrays.deepHashCode(this)
|
||||
|
||||
Reference in New Issue
Block a user