Provide protected toArray implementation in AbstractCollection.
Relates to #KT-13898
This commit is contained in:
@@ -31,7 +31,14 @@ public abstract class AbstractCollection<out E> protected constructor() : Collec
|
||||
if (it === this) "(this Collection)" else it.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array of type `Array<Any?>` with the elements of this collection.
|
||||
*/
|
||||
protected open fun toArray(): Array<Any?> = copyToArrayImpl(this)
|
||||
|
||||
/**
|
||||
* Fills the provided [array] or creates new array of the same type
|
||||
* and fills it with the elements of this collection.
|
||||
*/
|
||||
protected open fun <T> toArray(array: Array<T>): Array<T> = copyToArrayImpl(this, array)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -182,6 +182,16 @@ internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
|
||||
else -> this
|
||||
}
|
||||
|
||||
@JvmVersion
|
||||
@kotlin.internal.InlineOnly
|
||||
internal inline fun copyToArrayImpl(collection: Collection<*>): Array<Any?> =
|
||||
kotlin.jvm.internal.CollectionToArray.toArray(collection)
|
||||
|
||||
@JvmVersion
|
||||
@kotlin.internal.InlineOnly
|
||||
internal inline fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> =
|
||||
kotlin.jvm.internal.CollectionToArray.toArray(collection, array)
|
||||
|
||||
// copies typed varargs array to array of objects
|
||||
@JvmVersion
|
||||
private fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array<Any?> =
|
||||
|
||||
Reference in New Issue
Block a user