Use annotation to distinct inline constructor
This commit is contained in:
committed by
KonstantinAnisimov
parent
31a24d4607
commit
ba1f3d502e
@@ -41,3 +41,11 @@ annotation class Intrinsic
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class ExportForCompiler
|
||||
|
||||
/**
|
||||
* Annotated constructor will be inlined.
|
||||
*/
|
||||
@Target(AnnotationTarget.CONSTRUCTOR)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class InlineConstructor
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package kotlin
|
||||
import konan.internal.ExportForCompiler
|
||||
import konan.internal.InlineConstructor
|
||||
|
||||
// TODO: remove that, as RTTI shall be per instantiation.
|
||||
@ExportTypeInfo("theArrayTypeInfo")
|
||||
public final class Array<T> {
|
||||
// Constructors are handled with compiler magic.
|
||||
public constructor(size: Int, init: (Int) -> T) {
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> T): this(size) {
|
||||
var index = 0
|
||||
while (index < size) {
|
||||
this[index] = init(index)
|
||||
|
||||
@@ -25,6 +25,7 @@ import kotlin.internal.PureReifiable
|
||||
import kotlin.util.sortArrayComparable
|
||||
import kotlin.util.sortArrayWith
|
||||
import kotlin.util.sortArray
|
||||
import konan.internal.InlineConstructor
|
||||
// TODO: make all iterator() methods inline.
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,7 @@ public final class ByteArray {
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
// TODO: What about inline constructors?
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Byte): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -92,6 +94,7 @@ public final class CharArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Char): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -142,6 +145,7 @@ public final class ShortArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Short): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -192,6 +196,7 @@ public final class IntArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Int): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -242,6 +247,7 @@ public final class LongArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Long): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -292,6 +298,7 @@ public final class FloatArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Float): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -338,6 +345,7 @@ public final class DoubleArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Double): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
@@ -384,6 +392,7 @@ public final class BooleanArray {
|
||||
* Creates a new array of the specified [size], where each element is calculated by calling the specified
|
||||
* [init] function. The [init] function returns an array element given its index.
|
||||
*/
|
||||
@InlineConstructor
|
||||
public constructor(size: Int, init: (Int) -> Boolean): this(size) {
|
||||
for (i in 0..size - 1) {
|
||||
this[i] = init(i)
|
||||
|
||||
Reference in New Issue
Block a user