Do not require array extensions being reified to create new array.

#KT-15377
This commit is contained in:
Ilya Gorbunov
2016-12-23 20:25:17 +03:00
parent 510295475b
commit 05dcaccf09
5 changed files with 12 additions and 5 deletions
+4 -1
View File
@@ -18,8 +18,11 @@ package kotlin.collections
import kotlin.comparisons.naturalOrder
/** Returns the array if it's not `null`, or an empty array otherwise. */
public inline fun <T> Array<out T>?.orEmpty(): Array<out T> = this ?: arrayOf<T>()
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
public inline fun <reified T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
public inline fun <T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
@JsName("copyToArray")
internal fun <T> copyToArray(collection: Collection<T>): Array<T> {
+1 -1
View File
@@ -19,7 +19,7 @@ package kotlin
/**
* Returns an empty array of the specified type [T].
*/
public inline fun <reified T> emptyArray(): Array<T> = js("[]")
public inline fun <T> emptyArray(): Array<T> = js("[]")
@library
public fun <T> arrayOf(vararg elements: T): Array<T> = noImpl
@@ -143,6 +143,10 @@ header abstract class AbstractMutableList<E> : MutableList<E> {
// From collections.kt
/** Returns the array if it's not `null`, or an empty array otherwise. */
header inline fun <reified T> Array<out T>?.orEmpty(): Array<out T>
header inline fun <reified T> Collection<T>.toTypedArray(): Array<T>
header fun <T : Comparable<T>> MutableList<T>.sort(): Unit
@@ -21,9 +21,6 @@
package kotlin.collections
/** Returns the array if it's not `null`, or an empty array otherwise. */
public inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: arrayOf<T>()
/**
* Returns a single list of all elements from all arrays in the given array.
@@ -23,6 +23,9 @@ package kotlin.collections
import java.nio.charset.Charset
/** Returns the array if it's not `null`, or an empty array otherwise. */
public inline fun <reified T> Array<out T>?.orEmpty(): Array<out T> = this ?: arrayOf<T>()
/**
* Converts the contents of this byte array to a string using the specified [charset].
*/