[JS IR BE] Implement *Array.plus(Collection<>) in typed Kotlin without dynamic helper

This commit is contained in:
Svyatoslav Kuzmich
2019-01-24 18:33:42 +03:00
parent 8c89ffbe2d
commit a5f537adc5
3 changed files with 44 additions and 15 deletions
@@ -1015,21 +1015,30 @@ public actual operator fun <T> Array<out T>.plus(elements: Collection<T>): Array
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public actual operator fun ByteArray.plus(elements: Collection<Byte>): ByteArray {
return fillFromCollection(this.copyOf(size + elements.size), this.size, elements)
var index = size
val result = this.copyOf(size + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public actual operator fun ShortArray.plus(elements: Collection<Short>): ShortArray {
return fillFromCollection(this.copyOf(size + elements.size), this.size, elements)
var index = size
val result = this.copyOf(size + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public actual operator fun IntArray.plus(elements: Collection<Int>): IntArray {
return fillFromCollection(this.copyOf(size + elements.size), this.size, elements)
var index = size
val result = this.copyOf(size + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
@@ -1043,14 +1052,20 @@ public actual operator fun LongArray.plus(elements: Collection<Long>): LongArray
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public actual operator fun FloatArray.plus(elements: Collection<Float>): FloatArray {
return fillFromCollection(this.copyOf(size + elements.size), this.size, elements)
var index = size
val result = this.copyOf(size + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public actual operator fun DoubleArray.plus(elements: Collection<Double>): DoubleArray {
return fillFromCollection(this.copyOf(size + elements.size), this.size, elements)
var index = size
val result = this.copyOf(size + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
@@ -1064,7 +1079,10 @@ public actual operator fun BooleanArray.plus(elements: Collection<Boolean>): Boo
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public actual operator fun CharArray.plus(elements: Collection<Char>): CharArray {
return fillFromCollection(this.copyOf(size + elements.size), this.size, elements)
var index = size
val result = this.copyOf(size + elements.size)
for (element in elements) result[index++] = element
return result
}
/**