Move copyToArrayImpl implementation to Common source set

This commit is contained in:
Abduqodiri Qurbonzoda
2023-06-01 13:26:08 +03:00
committed by Space Team
parent 6fdfd4e8dd
commit 7010bf2c20
5 changed files with 40 additions and 53 deletions
@@ -18,17 +18,4 @@ public actual inline fun <reified T> Collection<T>.toTypedArray(): Array<T> {
for (element in this) result[index++] = element
@Suppress("UNCHECKED_CAST")
return result as Array<T>
}
@Suppress("UNCHECKED_CAST")
internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> {
if (array.size < collection.size)
return copyToArrayImpl(collection) as Array<T>
val iterator = collection.iterator()
var index = 0
while (iterator.hasNext()) {
array[index++] = iterator.next() as T
}
return terminateCollectionToArray(collection.size, array)
}