Added inline function "Array" into stdlib
It has the same signature and semantics as Array constructor had Also made Array constructor private and accepting no arguments
This commit is contained in:
committed by
Alexander Udalov
parent
654411a0b0
commit
d345ba05dd
@@ -14,7 +14,7 @@ public open class Any {
|
||||
}
|
||||
|
||||
public final class Array</*0*/ reified T> : kotlin.Cloneable {
|
||||
/*primary*/ public constructor Array</*0*/ reified T>(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, T>)
|
||||
/*primary*/ private constructor Array</*0*/ reified T>()
|
||||
public open override /*1*/ fun clone(): kotlin.Array<T>
|
||||
public final fun get(/*0*/ index: kotlin.Int): T
|
||||
public final fun iterator(): kotlin.Iterator<T>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
public class Array<reified T>(size: Int, init: (Int) -> T) : Cloneable {
|
||||
public class Array<reified T> private (): Cloneable {
|
||||
public fun get(index: Int): T
|
||||
public fun set(index: Int, value: T): Unit
|
||||
|
||||
|
||||
-5
@@ -49,9 +49,6 @@ public final class ArrayFIF extends CompositeFIF {
|
||||
@NotNull
|
||||
private static final NamePredicate LONG_ARRAY;
|
||||
|
||||
@NotNull
|
||||
private static final NamePredicate ARRAY;
|
||||
|
||||
@NotNull
|
||||
private static final NamePredicate ARRAYS;
|
||||
|
||||
@@ -78,7 +75,6 @@ public final class ArrayFIF extends CompositeFIF {
|
||||
CHAR_ARRAY = new NamePredicate(charArrayName);
|
||||
BOOLEAN_ARRAY = new NamePredicate(booleanArrayName);
|
||||
LONG_ARRAY = new NamePredicate(longArrayName);
|
||||
ARRAY = new NamePredicate(arrayName);
|
||||
|
||||
arrayTypeNames.add(charArrayName);
|
||||
arrayTypeNames.add(booleanArrayName);
|
||||
@@ -139,7 +135,6 @@ public final class ArrayFIF extends CompositeFIF {
|
||||
add(pattern(ARRAYS, "set"), SET_INTRINSIC);
|
||||
add(pattern(ARRAYS, "size"), LENGTH_PROPERTY_INTRINSIC);
|
||||
add(pattern(ARRAYS, "iterator"), new KotlinFunctionIntrinsic("arrayIterator"));
|
||||
add(pattern(ARRAY, "<init>"), new KotlinFunctionIntrinsic("arrayFromFun"));
|
||||
add(pattern(NUMBER_ARRAY, "<init>"),new KotlinFunctionIntrinsic("numberArrayOfSize"));
|
||||
add(pattern(CHAR_ARRAY, "<init>"), new KotlinFunctionIntrinsic("charArrayOfSize"));
|
||||
add(pattern(BOOLEAN_ARRAY, "<init>"), new KotlinFunctionIntrinsic("booleanArrayOfSize"));
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
package kotlin
|
||||
|
||||
public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
||||
val result = arrayOfNulls<T>(size)
|
||||
|
||||
for (i in 0..size - 1) {
|
||||
result[i] = init(i)
|
||||
}
|
||||
|
||||
return result as Array<T>
|
||||
}
|
||||
|
||||
public val BooleanArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user