Refactor: replace Math.min with minOf in common code.

Add temporary import of kotlin.comparisons where required.
This commit is contained in:
Ilya Gorbunov
2016-11-16 07:49:14 +03:00
parent 51c24a0c3c
commit 844c68286a
11 changed files with 74 additions and 78 deletions
+26 -26
View File
@@ -11601,7 +11601,7 @@ public infix fun <R> CharArray.zip(other: Array<out R>): List<Pair<Char, R>> {
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <T, R, V> Array<out T>.zip(other: Array<out R>, transform: (T, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11613,7 +11613,7 @@ public inline fun <T, R, V> Array<out T>.zip(other: Array<out R>, transform: (T,
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> ByteArray.zip(other: Array<out R>, transform: (Byte, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11625,7 +11625,7 @@ public inline fun <R, V> ByteArray.zip(other: Array<out R>, transform: (Byte, R)
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> ShortArray.zip(other: Array<out R>, transform: (Short, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11637,7 +11637,7 @@ public inline fun <R, V> ShortArray.zip(other: Array<out R>, transform: (Short,
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> IntArray.zip(other: Array<out R>, transform: (Int, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11649,7 +11649,7 @@ public inline fun <R, V> IntArray.zip(other: Array<out R>, transform: (Int, R) -
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> LongArray.zip(other: Array<out R>, transform: (Long, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11661,7 +11661,7 @@ public inline fun <R, V> LongArray.zip(other: Array<out R>, transform: (Long, R)
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> FloatArray.zip(other: Array<out R>, transform: (Float, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11673,7 +11673,7 @@ public inline fun <R, V> FloatArray.zip(other: Array<out R>, transform: (Float,
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> DoubleArray.zip(other: Array<out R>, transform: (Double, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11685,7 +11685,7 @@ public inline fun <R, V> DoubleArray.zip(other: Array<out R>, transform: (Double
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> BooleanArray.zip(other: Array<out R>, transform: (Boolean, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11697,7 +11697,7 @@ public inline fun <R, V> BooleanArray.zip(other: Array<out R>, transform: (Boole
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <R, V> CharArray.zip(other: Array<out R>, transform: (Char, R) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11773,7 +11773,7 @@ public infix fun <R> CharArray.zip(other: Iterable<R>): List<Pair<Char, R>> {
*/
public inline fun <T, R, V> Array<out T>.zip(other: Iterable<R>, transform: (T, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11787,7 +11787,7 @@ public inline fun <T, R, V> Array<out T>.zip(other: Iterable<R>, transform: (T,
*/
public inline fun <R, V> ByteArray.zip(other: Iterable<R>, transform: (Byte, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11801,7 +11801,7 @@ public inline fun <R, V> ByteArray.zip(other: Iterable<R>, transform: (Byte, R)
*/
public inline fun <R, V> ShortArray.zip(other: Iterable<R>, transform: (Short, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11815,7 +11815,7 @@ public inline fun <R, V> ShortArray.zip(other: Iterable<R>, transform: (Short, R
*/
public inline fun <R, V> IntArray.zip(other: Iterable<R>, transform: (Int, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11829,7 +11829,7 @@ public inline fun <R, V> IntArray.zip(other: Iterable<R>, transform: (Int, R) ->
*/
public inline fun <R, V> LongArray.zip(other: Iterable<R>, transform: (Long, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11843,7 +11843,7 @@ public inline fun <R, V> LongArray.zip(other: Iterable<R>, transform: (Long, R)
*/
public inline fun <R, V> FloatArray.zip(other: Iterable<R>, transform: (Float, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11857,7 +11857,7 @@ public inline fun <R, V> FloatArray.zip(other: Iterable<R>, transform: (Float, R
*/
public inline fun <R, V> DoubleArray.zip(other: Iterable<R>, transform: (Double, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11871,7 +11871,7 @@ public inline fun <R, V> DoubleArray.zip(other: Iterable<R>, transform: (Double,
*/
public inline fun <R, V> BooleanArray.zip(other: Iterable<R>, transform: (Boolean, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11885,7 +11885,7 @@ public inline fun <R, V> BooleanArray.zip(other: Iterable<R>, transform: (Boolea
*/
public inline fun <R, V> CharArray.zip(other: Iterable<R>, transform: (Char, R) -> V): List<V> {
val arraySize = size
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(other.collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in other) {
if (i >= arraySize) break
@@ -11954,7 +11954,7 @@ public infix fun CharArray.zip(other: CharArray): List<Pair<Char, Char>> {
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> ByteArray.zip(other: ByteArray, transform: (Byte, Byte) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11966,7 +11966,7 @@ public inline fun <V> ByteArray.zip(other: ByteArray, transform: (Byte, Byte) ->
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> ShortArray.zip(other: ShortArray, transform: (Short, Short) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11978,7 +11978,7 @@ public inline fun <V> ShortArray.zip(other: ShortArray, transform: (Short, Short
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> IntArray.zip(other: IntArray, transform: (Int, Int) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -11990,7 +11990,7 @@ public inline fun <V> IntArray.zip(other: IntArray, transform: (Int, Int) -> V):
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> LongArray.zip(other: LongArray, transform: (Long, Long) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -12002,7 +12002,7 @@ public inline fun <V> LongArray.zip(other: LongArray, transform: (Long, Long) ->
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> FloatArray.zip(other: FloatArray, transform: (Float, Float) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -12014,7 +12014,7 @@ public inline fun <V> FloatArray.zip(other: FloatArray, transform: (Float, Float
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> DoubleArray.zip(other: DoubleArray, transform: (Double, Double) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -12026,7 +12026,7 @@ public inline fun <V> DoubleArray.zip(other: DoubleArray, transform: (Double, Do
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> BooleanArray.zip(other: BooleanArray, transform: (Boolean, Boolean) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -12038,7 +12038,7 @@ public inline fun <V> BooleanArray.zip(other: BooleanArray, transform: (Boolean,
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
public inline fun <V> CharArray.zip(other: CharArray, transform: (Char, Char) -> V): List<V> {
val size = Math.min(size, other.size)
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], other[i]))
@@ -1871,7 +1871,7 @@ public infix fun <T, R> Iterable<T>.zip(other: Array<out R>): List<Pair<T, R>> {
*/
public inline fun <T, R, V> Iterable<T>.zip(other: Array<out R>, transform: (T, R) -> V): List<V> {
val arraySize = other.size
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), arraySize))
val list = ArrayList<V>(minOf(collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in this) {
if (i >= arraySize) break
@@ -1893,7 +1893,7 @@ public infix fun <T, R> Iterable<T>.zip(other: Iterable<R>): List<Pair<T, R>> {
public inline fun <T, R, V> Iterable<T>.zip(other: Iterable<R>, transform: (T, R) -> V): List<V> {
val first = iterator()
val second = other.iterator()
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
val list = ArrayList<V>(minOf(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
while (first.hasNext() && second.hasNext()) {
list.add(transform(first.next(), second.next()))
}
@@ -1135,7 +1135,7 @@ public infix fun CharSequence.zip(other: CharSequence): List<Pair<Char, Char>> {
* Returns a list of values built from characters of both char sequences with same indexes using provided [transform]. List has length of shortest char sequence.
*/
public inline fun <V> CharSequence.zip(other: CharSequence, transform: (Char, Char) -> V): List<V> {
val length = Math.min(this.length, other.length)
val length = minOf(this.length, other.length)
val list = ArrayList<V>(length)
for (i in 0..length-1) {
list.add(transform(this[i], other[i]))