Implement asList, slice & sliceArray extension functions for UArrays
This commit is contained in:
committed by
Ilya Gorbunov
parent
114736c09b
commit
fc85781bfc
+20
@@ -2287,6 +2287,10 @@ public abstract class kotlin/collections/ShortIterator : java/util/Iterator, kot
|
||||
}
|
||||
|
||||
public final class kotlin/collections/UArraysKt {
|
||||
public static final fun asList--ajY-9A ([I)Ljava/util/List;
|
||||
public static final fun asList-GBYM_sE ([B)Ljava/util/List;
|
||||
public static final fun asList-QwZRm1k ([J)Ljava/util/List;
|
||||
public static final fun asList-rL5Bavg ([S)Ljava/util/List;
|
||||
public static final fun binarySearch-2fe2U9s ([IIII)I
|
||||
public static synthetic fun binarySearch-2fe2U9s$default ([IIIIILjava/lang/Object;)I
|
||||
public static final fun binarySearch-EtDCXyQ ([SSII)I
|
||||
@@ -2343,6 +2347,22 @@ public final class kotlin/collections/UArraysKt {
|
||||
public static final fun singleOrNull-GBYM_sE ([B)Lkotlin/UByte;
|
||||
public static final fun singleOrNull-QwZRm1k ([J)Lkotlin/ULong;
|
||||
public static final fun singleOrNull-rL5Bavg ([S)Lkotlin/UShort;
|
||||
public static final fun slice-F7u83W8 ([JLjava/lang/Iterable;)Ljava/util/List;
|
||||
public static final fun slice-HwE9HBo ([ILjava/lang/Iterable;)Ljava/util/List;
|
||||
public static final fun slice-JGPC0-M ([SLjava/lang/Iterable;)Ljava/util/List;
|
||||
public static final fun slice-JQknh5Q ([BLjava/lang/Iterable;)Ljava/util/List;
|
||||
public static final fun slice-Q6IL4kU ([SLkotlin/ranges/IntRange;)Ljava/util/List;
|
||||
public static final fun slice-ZRhS8yI ([JLkotlin/ranges/IntRange;)Ljava/util/List;
|
||||
public static final fun slice-c0bezYM ([BLkotlin/ranges/IntRange;)Ljava/util/List;
|
||||
public static final fun slice-tAntMlw ([ILkotlin/ranges/IntRange;)Ljava/util/List;
|
||||
public static final fun sliceArray-CFIt9YE ([ILjava/util/Collection;)[I
|
||||
public static final fun sliceArray-Q6IL4kU ([SLkotlin/ranges/IntRange;)[S
|
||||
public static final fun sliceArray-ZRhS8yI ([JLkotlin/ranges/IntRange;)[J
|
||||
public static final fun sliceArray-c0bezYM ([BLkotlin/ranges/IntRange;)[B
|
||||
public static final fun sliceArray-kzHmqpY ([JLjava/util/Collection;)[J
|
||||
public static final fun sliceArray-ojwP5H8 ([SLjava/util/Collection;)[S
|
||||
public static final fun sliceArray-tAntMlw ([ILkotlin/ranges/IntRange;)[I
|
||||
public static final fun sliceArray-xo_DsdI ([BLjava/util/Collection;)[B
|
||||
public static final fun toTypedArray--ajY-9A ([I)[Lkotlin/UInt;
|
||||
public static final fun toTypedArray-GBYM_sE ([B)[Lkotlin/UByte;
|
||||
public static final fun toTypedArray-QwZRm1k ([J)[Lkotlin/ULong;
|
||||
|
||||
@@ -1147,7 +1147,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
|
||||
|
||||
val f_asList = fn("asList()") {
|
||||
include(ArraysOfObjects, ArraysOfPrimitives)
|
||||
include(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns a [List] that wraps the original array." }
|
||||
returns("List<T>")
|
||||
@@ -1168,13 +1168,33 @@ object ArrayOps : TemplateGroupBase() {
|
||||
override fun lastIndexOf(element: T): Int = this@asList.lastIndexOf(element)
|
||||
}
|
||||
"""
|
||||
specialFor(ArraysOfPrimitives) {
|
||||
specialFor(ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
on(Platform.JVM) {
|
||||
body { objectLiteralImpl }
|
||||
}
|
||||
on(Platform.JS) {
|
||||
if (primitive == PrimitiveType.Char) {
|
||||
body { objectLiteralImpl }
|
||||
if (primitive == PrimitiveType.Char || primitive in PrimitiveType.unsignedPrimitives) {
|
||||
body {
|
||||
"""
|
||||
return object : AbstractList<T>(), RandomAccess {
|
||||
override val size: Int get() = this@asList.size
|
||||
override fun isEmpty(): Boolean = this@asList.isEmpty()
|
||||
override fun contains(element: T): Boolean = this@asList.contains(element)
|
||||
override fun get(index: Int): T {
|
||||
AbstractList.checkElementIndex(index, size)
|
||||
return this@asList[index]
|
||||
}
|
||||
override fun indexOf(element: T): Int {
|
||||
if ((element as Any?) !is T) return -1
|
||||
return this@asList.indexOf(element)
|
||||
}
|
||||
override fun lastIndexOf(element: T): Int {
|
||||
if ((element as Any?) !is T) return -1
|
||||
return this@asList.lastIndexOf(element)
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
else {
|
||||
inlineOnly()
|
||||
|
||||
@@ -17,6 +17,11 @@ object Filtering : TemplateGroupBase() {
|
||||
sequenceClassification(terminal)
|
||||
else
|
||||
sequenceClassification(intermediate, stateless)
|
||||
|
||||
specialFor(ArraysOfUnsigned) {
|
||||
since("1.3")
|
||||
annotation("@ExperimentalUnsignedTypes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -832,7 +837,7 @@ object Filtering : TemplateGroupBase() {
|
||||
|
||||
|
||||
val f_slice = fn("slice(indices: Iterable<Int>)") {
|
||||
include(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
include(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns a list containing elements at specified [indices]." }
|
||||
returns("List<T>")
|
||||
@@ -870,7 +875,7 @@ object Filtering : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_slice_range = fn("slice(indices: IntRange)") {
|
||||
include(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
include(CharSequences, Strings, Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns a list containing elements at indices in the specified [indices] range." }
|
||||
returns("List<T>")
|
||||
@@ -880,7 +885,7 @@ object Filtering : TemplateGroupBase() {
|
||||
return this.subList(indices.start, indices.endInclusive + 1).toList()
|
||||
"""
|
||||
}
|
||||
body(ArraysOfPrimitives, ArraysOfObjects) {
|
||||
body(ArraysOfPrimitives, ArraysOfObjects, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (indices.isEmpty()) return listOf()
|
||||
return copyOfRange(indices.start, indices.endInclusive + 1).asList()
|
||||
@@ -900,7 +905,7 @@ object Filtering : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_sliceArray = fn("sliceArray(indices: Collection<Int>)") {
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns an array containing elements of this array at specified [indices]." }
|
||||
returns("SELF")
|
||||
@@ -924,12 +929,17 @@ object Filtering : TemplateGroupBase() {
|
||||
return result
|
||||
"""
|
||||
}
|
||||
body(ArraysOfUnsigned) {
|
||||
"""
|
||||
return SELF(storage.sliceArray(indices))
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
val f_sliceArrayRange = fn("sliceArray(indices: IntRange)") {
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns a list containing elements at indices in the specified [indices] range." }
|
||||
doc { "Returns an array containing elements at indices in the specified [indices] range." }
|
||||
returns("SELF")
|
||||
body(InvariantArraysOfObjects) {
|
||||
"""
|
||||
@@ -943,5 +953,10 @@ object Filtering : TemplateGroupBase() {
|
||||
return copyOfRange(indices.start, indices.endInclusive + 1)
|
||||
"""
|
||||
}
|
||||
body(ArraysOfUnsigned) {
|
||||
"""
|
||||
return SELF(storage.sliceArray(indices))
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user