Implement conversion from typed array and collection to UArrays

This commit is contained in:
Abduqodiri Qurbonzoda
2019-01-25 15:40:12 +03:00
committed by Ilya Gorbunov
parent bbaabb90e4
commit 299fac8e2d
8 changed files with 155 additions and 38 deletions
@@ -2327,6 +2327,10 @@ public final class kotlin/collections/UArraysKt {
public static final fun toTypedArray-GBYM_sE ([B)[Lkotlin/UByte;
public static final fun toTypedArray-QwZRm1k ([J)[Lkotlin/ULong;
public static final fun toTypedArray-rL5Bavg ([S)[Lkotlin/UShort;
public static final fun toUByteArray ([Lkotlin/UByte;)[B
public static final fun toUIntArray ([Lkotlin/UInt;)[I
public static final fun toULongArray ([Lkotlin/ULong;)[J
public static final fun toUShortArray ([Lkotlin/UShort;)[S
}
public abstract class kotlin/collections/UByteIterator : java/util/Iterator, kotlin/jvm/internal/markers/KMappedMarker {
@@ -2337,6 +2341,13 @@ public abstract class kotlin/collections/UByteIterator : java/util/Iterator, kot
public fun remove ()V
}
public final class kotlin/collections/UCollectionsKt {
public static final fun toUByteArray (Ljava/util/Collection;)[B
public static final fun toUIntArray (Ljava/util/Collection;)[I
public static final fun toULongArray (Ljava/util/Collection;)[J
public static final fun toUShortArray (Ljava/util/Collection;)[S
}
public abstract class kotlin/collections/UIntIterator : java/util/Iterator, kotlin/jvm/internal/markers/KMappedMarker {
public fun <init> ()V
public synthetic fun next ()Ljava/lang/Object;
@@ -322,26 +322,35 @@ object ArrayOps : TemplateGroupBase() {
}
val f_toPrimitiveArray = fn("toPrimitiveArray()") {
include(ArraysOfObjects, PrimitiveType.defaultPrimitives)
include(Collections, PrimitiveType.defaultPrimitives)
include(ArraysOfObjects, PrimitiveType.values().toSet())
include(Collections, PrimitiveType.values().toSet())
} builder {
val primitive = checkNotNull(primitive)
val arrayType = primitive.name + "Array"
signature("to$arrayType()")
returns(arrayType)
if (primitive in PrimitiveType.unsignedPrimitives) {
since("1.3")
annotation("@ExperimentalUnsignedTypes")
}
// TODO: Use different implementations for JS
specialFor(ArraysOfObjects) {
if (primitive in PrimitiveType.unsignedPrimitives) {
sourceFile(SourceFile.UArrays)
}
doc { "Returns an array of ${primitive.name} containing all of the elements of this generic array." }
body {
"""
val result = $arrayType(size)
for (index in indices)
result[index] = this[index]
return result
return $arrayType(size) { index -> this[index] }
"""
}
}
specialFor(Collections) {
if (primitive in PrimitiveType.unsignedPrimitives) {
sourceFile(SourceFile.UCollections)
}
doc { "Returns an array of ${primitive.name} containing all of the elements of this collection." }
body {
"""
@@ -10,6 +10,7 @@ enum class SourceFile(jvmClassName: String? = null, val multifile: Boolean = tru
Arrays(packageName = "kotlin.collections"),
UArrays(packageName = "kotlin.collections"),
Collections(packageName = "kotlin.collections"),
UCollections(packageName = "kotlin.collections"),
Sets(packageName = "kotlin.collections"),
Maps(packageName = "kotlin.collections"),
Sequences(packageName = "kotlin.sequences"),