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
@@ -22,17 +22,4 @@ internal fun <T> copyToArray(collection: Collection<T>): Array<T> =
//TODO: Find more proper way to call abstract collection's toArray
@Suppress("INVISIBLE_MEMBER") collection.toArray() as Array<T>
else
copyToArrayImpl(collection) 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)
}
copyToArrayImpl(collection) as Array<T>