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
@@ -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"),