diff --git a/js/js.libraries/src/core/builtins.kt b/js/js.libraries/src/core/builtins.kt index d7316b2c24b..bca6e4d3d77 100644 --- a/js/js.libraries/src/core/builtins.kt +++ b/js/js.libraries/src/core/builtins.kt @@ -158,7 +158,7 @@ internal class BoxedChar(val c: Int) : Comparable { @kotlin.internal.InlineOnly internal inline fun concat(args: Array): T { val typed = js("Array")(args.size) - for (i in 0..args.size - 1) { + for (i in args.indices) { val arr = args[i] if (arr !is Array<*>) { typed[i] = js("[]").slice.call(arr) @@ -196,15 +196,15 @@ internal fun primitiveArrayConcat(a: T, b: T): T { } else { var size = 0 - for (i in 0..args.size - 1) { + for (i in args.indices) { size += args[i].asDynamic().length as Int } val result = js("new a.constructor(size)") kotlin.copyArrayType(a, result) size = 0 - for (i in 0..args.size - 1) { + for (i in args.indices) { val arr = args[i].asDynamic() - for (j in 0..arr.length - 1) { + for (j in 0 until arr.length) { result[size++] = arr[j] } } diff --git a/js/js.libraries/src/core/collections/InternalHashCodeMap.kt b/js/js.libraries/src/core/collections/InternalHashCodeMap.kt index 2efae41dfa3..fdd89846e59 100644 --- a/js/js.libraries/src/core/collections/InternalHashCodeMap.kt +++ b/js/js.libraries/src/core/collections/InternalHashCodeMap.kt @@ -92,7 +92,7 @@ internal class InternalHashCodeMap(override val equality: EqualityComparat } else { val chain: Array> = chainOrEntry - for (index in 0..chain.size - 1) { + for (index in chain.indices) { val entry = chain[index] if (equality.equals(key, entry.key)) { if (chain.size == 1) { diff --git a/js/js.libraries/src/core/generated/_ArraysJs.kt b/js/js.libraries/src/core/generated/_ArraysJs.kt index d7b13651452..08df7d86716 100644 --- a/js/js.libraries/src/core/generated/_ArraysJs.kt +++ b/js/js.libraries/src/core/generated/_ArraysJs.kt @@ -3948,7 +3948,7 @@ public fun Array.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -3963,7 +3963,7 @@ public fun ByteArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -3978,7 +3978,7 @@ public fun ShortArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -3993,7 +3993,7 @@ public fun IntArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4008,7 +4008,7 @@ public fun LongArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4023,7 +4023,7 @@ public fun FloatArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4038,7 +4038,7 @@ public fun DoubleArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4053,7 +4053,7 @@ public fun BooleanArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4068,7 +4068,7 @@ public fun CharArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -11729,7 +11729,7 @@ public infix fun CharArray.zip(other: Array): List> { public inline fun Array.zip(other: Array, transform: (a: T, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11741,7 +11741,7 @@ public inline fun Array.zip(other: Array, transform: (a: public inline fun ByteArray.zip(other: Array, transform: (a: Byte, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11753,7 +11753,7 @@ public inline fun ByteArray.zip(other: Array, transform: (a: Byte, public inline fun ShortArray.zip(other: Array, transform: (a: Short, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11765,7 +11765,7 @@ public inline fun ShortArray.zip(other: Array, transform: (a: Shor public inline fun IntArray.zip(other: Array, transform: (a: Int, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11777,7 +11777,7 @@ public inline fun IntArray.zip(other: Array, transform: (a: Int, b public inline fun LongArray.zip(other: Array, transform: (a: Long, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11789,7 +11789,7 @@ public inline fun LongArray.zip(other: Array, transform: (a: Long, public inline fun FloatArray.zip(other: Array, transform: (a: Float, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11801,7 +11801,7 @@ public inline fun FloatArray.zip(other: Array, transform: (a: Floa public inline fun DoubleArray.zip(other: Array, transform: (a: Double, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11813,7 +11813,7 @@ public inline fun DoubleArray.zip(other: Array, transform: (a: Dou public inline fun BooleanArray.zip(other: Array, transform: (a: Boolean, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11825,7 +11825,7 @@ public inline fun BooleanArray.zip(other: Array, transform: (a: Bo public inline fun CharArray.zip(other: Array, transform: (a: Char, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12082,7 +12082,7 @@ public infix fun CharArray.zip(other: CharArray): List> { public inline fun ByteArray.zip(other: ByteArray, transform: (a: Byte, b: Byte) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12094,7 +12094,7 @@ public inline fun ByteArray.zip(other: ByteArray, transform: (a: Byte, b: By public inline fun ShortArray.zip(other: ShortArray, transform: (a: Short, b: Short) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12106,7 +12106,7 @@ public inline fun ShortArray.zip(other: ShortArray, transform: (a: Short, b: public inline fun IntArray.zip(other: IntArray, transform: (a: Int, b: Int) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12118,7 +12118,7 @@ public inline fun IntArray.zip(other: IntArray, transform: (a: Int, b: Int) public inline fun LongArray.zip(other: LongArray, transform: (a: Long, b: Long) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12130,7 +12130,7 @@ public inline fun LongArray.zip(other: LongArray, transform: (a: Long, b: Lo public inline fun FloatArray.zip(other: FloatArray, transform: (a: Float, b: Float) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12142,7 +12142,7 @@ public inline fun FloatArray.zip(other: FloatArray, transform: (a: Float, b: public inline fun DoubleArray.zip(other: DoubleArray, transform: (a: Double, b: Double) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12154,7 +12154,7 @@ public inline fun DoubleArray.zip(other: DoubleArray, transform: (a: Double, public inline fun BooleanArray.zip(other: BooleanArray, transform: (a: Boolean, b: Boolean) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12166,7 +12166,7 @@ public inline fun BooleanArray.zip(other: BooleanArray, transform: (a: Boole public inline fun CharArray.zip(other: CharArray, transform: (a: Char, b: Char) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list diff --git a/js/js.libraries/src/core/generated/_CollectionsJs.kt b/js/js.libraries/src/core/generated/_CollectionsJs.kt index ad4d47ae579..f1209c165b7 100644 --- a/js/js.libraries/src/core/generated/_CollectionsJs.kt +++ b/js/js.libraries/src/core/generated/_CollectionsJs.kt @@ -551,7 +551,7 @@ public fun Iterable.drop(n: Int): List { list = ArrayList(resultSize) if (this is List) { if (this is RandomAccess) { - for (index in n..size - 1) + for (index in n until size) list.add(this[index]) } else { for (item in listIterator(n)) @@ -742,7 +742,7 @@ public fun List.takeLast(n: Int): List { if (n == 1) return listOf(last()) val list = ArrayList(n) if (this is RandomAccess) { - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) } else { for (item in listIterator(size - n)) diff --git a/js/js.libraries/src/core/generated/_StringsJs.kt b/js/js.libraries/src/core/generated/_StringsJs.kt index 8410c2ba734..576ee758f58 100644 --- a/js/js.libraries/src/core/generated/_StringsJs.kt +++ b/js/js.libraries/src/core/generated/_StringsJs.kt @@ -253,7 +253,7 @@ public fun String.dropLast(n: Int): String { * Returns a subsequence of this char sequence containing all characters except last characters that satisfy the given [predicate]. */ public inline fun CharSequence.dropLastWhile(predicate: (Char) -> Boolean): CharSequence { - for (index in this.indices.reversed()) + for (index in lastIndex downTo 0) if (!predicate(this[index])) return subSequence(0, index + 1) return "" @@ -263,7 +263,7 @@ public inline fun CharSequence.dropLastWhile(predicate: (Char) -> Boolean): Char * Returns a string containing all characters except last characters that satisfy the given [predicate]. */ public inline fun String.dropLastWhile(predicate: (Char) -> Boolean): String { - for (index in this.indices.reversed()) + for (index in lastIndex downTo 0) if (!predicate(this[index])) return substring(0, index + 1) return "" @@ -359,7 +359,7 @@ public inline fun CharSequence.filterNotTo(destination: C, pred * Appends all characters matching the given [predicate] to the given [destination]. */ public inline fun CharSequence.filterTo(destination: C, predicate: (Char) -> Boolean): C { - for (index in 0..length - 1) { + for (index in 0 until length) { val element = get(index) if (predicate(element)) destination.append(element) } @@ -465,7 +465,7 @@ public inline fun String.takeLastWhile(predicate: (Char) -> Boolean): String { * Returns a subsequence of this char sequence containing the first characters that satisfy the given [predicate]. */ public inline fun CharSequence.takeWhile(predicate: (Char) -> Boolean): CharSequence { - for (index in 0..length - 1) + for (index in 0 until length) if (!predicate(get(index))) { return subSequence(0, index) } @@ -476,7 +476,7 @@ public inline fun CharSequence.takeWhile(predicate: (Char) -> Boolean): CharSequ * Returns a string containing the first characters that satisfy the given [predicate]. */ public inline fun String.takeWhile(predicate: (Char) -> Boolean): String { - for (index in 0..length - 1) + for (index in 0 until length) if (!predicate(get(index))) { return substring(0, index) } @@ -1313,7 +1313,7 @@ public infix fun CharSequence.zip(other: CharSequence): List> { public inline fun CharSequence.zip(other: CharSequence, transform: (a: Char, b: Char) -> V): List { val length = minOf(this.length, other.length) val list = ArrayList(length) - for (i in 0..length-1) { + for (i in 0 until length) { list.add(transform(this[i], other[i])) } return list @@ -1344,7 +1344,7 @@ public inline fun CharSequence.zipWithNext(transform: (a: Char, b: Char) -> val size = length - 1 if (size < 1) return emptyList() val result = ArrayList(size) - for (index in 0..size - 1) { + for (index in 0 until size) { result.add(transform(this[index], this[index + 1])) } return result diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index ae33efda44f..bec2f48a2f0 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -3946,7 +3946,7 @@ public fun Array.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -3961,7 +3961,7 @@ public fun ByteArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -3976,7 +3976,7 @@ public fun ShortArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -3991,7 +3991,7 @@ public fun IntArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4006,7 +4006,7 @@ public fun LongArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4021,7 +4021,7 @@ public fun FloatArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4036,7 +4036,7 @@ public fun DoubleArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4051,7 +4051,7 @@ public fun BooleanArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -4066,7 +4066,7 @@ public fun CharArray.takeLast(n: Int): List { if (n >= size) return toList() if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list } @@ -11799,7 +11799,7 @@ public infix fun CharArray.zip(other: Array): List> { public inline fun Array.zip(other: Array, transform: (a: T, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11811,7 +11811,7 @@ public inline fun Array.zip(other: Array, transform: (a: public inline fun ByteArray.zip(other: Array, transform: (a: Byte, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11823,7 +11823,7 @@ public inline fun ByteArray.zip(other: Array, transform: (a: Byte, public inline fun ShortArray.zip(other: Array, transform: (a: Short, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11835,7 +11835,7 @@ public inline fun ShortArray.zip(other: Array, transform: (a: Shor public inline fun IntArray.zip(other: Array, transform: (a: Int, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11847,7 +11847,7 @@ public inline fun IntArray.zip(other: Array, transform: (a: Int, b public inline fun LongArray.zip(other: Array, transform: (a: Long, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11859,7 +11859,7 @@ public inline fun LongArray.zip(other: Array, transform: (a: Long, public inline fun FloatArray.zip(other: Array, transform: (a: Float, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11871,7 +11871,7 @@ public inline fun FloatArray.zip(other: Array, transform: (a: Floa public inline fun DoubleArray.zip(other: Array, transform: (a: Double, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11883,7 +11883,7 @@ public inline fun DoubleArray.zip(other: Array, transform: (a: Dou public inline fun BooleanArray.zip(other: Array, transform: (a: Boolean, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -11895,7 +11895,7 @@ public inline fun BooleanArray.zip(other: Array, transform: (a: Bo public inline fun CharArray.zip(other: Array, transform: (a: Char, b: R) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12152,7 +12152,7 @@ public infix fun CharArray.zip(other: CharArray): List> { public inline fun ByteArray.zip(other: ByteArray, transform: (a: Byte, b: Byte) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12164,7 +12164,7 @@ public inline fun ByteArray.zip(other: ByteArray, transform: (a: Byte, b: By public inline fun ShortArray.zip(other: ShortArray, transform: (a: Short, b: Short) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12176,7 +12176,7 @@ public inline fun ShortArray.zip(other: ShortArray, transform: (a: Short, b: public inline fun IntArray.zip(other: IntArray, transform: (a: Int, b: Int) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12188,7 +12188,7 @@ public inline fun IntArray.zip(other: IntArray, transform: (a: Int, b: Int) public inline fun LongArray.zip(other: LongArray, transform: (a: Long, b: Long) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12200,7 +12200,7 @@ public inline fun LongArray.zip(other: LongArray, transform: (a: Long, b: Lo public inline fun FloatArray.zip(other: FloatArray, transform: (a: Float, b: Float) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12212,7 +12212,7 @@ public inline fun FloatArray.zip(other: FloatArray, transform: (a: Float, b: public inline fun DoubleArray.zip(other: DoubleArray, transform: (a: Double, b: Double) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12224,7 +12224,7 @@ public inline fun DoubleArray.zip(other: DoubleArray, transform: (a: Double, public inline fun BooleanArray.zip(other: BooleanArray, transform: (a: Boolean, b: Boolean) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -12236,7 +12236,7 @@ public inline fun BooleanArray.zip(other: BooleanArray, transform: (a: Boole public inline fun CharArray.zip(other: CharArray, transform: (a: Char, b: Char) -> V): List { val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 7959d2d7e8c..aa8d9d45079 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -551,7 +551,7 @@ public fun Iterable.drop(n: Int): List { list = ArrayList(resultSize) if (this is List) { if (this is RandomAccess) { - for (index in n..size - 1) + for (index in n until size) list.add(this[index]) } else { for (item in listIterator(n)) @@ -742,7 +742,7 @@ public fun List.takeLast(n: Int): List { if (n == 1) return listOf(last()) val list = ArrayList(n) if (this is RandomAccess) { - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) } else { for (item in listIterator(size - n)) diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index 30553f41956..6aade189aa3 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -253,7 +253,7 @@ public fun String.dropLast(n: Int): String { * Returns a subsequence of this char sequence containing all characters except last characters that satisfy the given [predicate]. */ public inline fun CharSequence.dropLastWhile(predicate: (Char) -> Boolean): CharSequence { - for (index in this.indices.reversed()) + for (index in lastIndex downTo 0) if (!predicate(this[index])) return subSequence(0, index + 1) return "" @@ -263,7 +263,7 @@ public inline fun CharSequence.dropLastWhile(predicate: (Char) -> Boolean): Char * Returns a string containing all characters except last characters that satisfy the given [predicate]. */ public inline fun String.dropLastWhile(predicate: (Char) -> Boolean): String { - for (index in this.indices.reversed()) + for (index in lastIndex downTo 0) if (!predicate(this[index])) return substring(0, index + 1) return "" @@ -359,7 +359,7 @@ public inline fun CharSequence.filterNotTo(destination: C, pred * Appends all characters matching the given [predicate] to the given [destination]. */ public inline fun CharSequence.filterTo(destination: C, predicate: (Char) -> Boolean): C { - for (index in 0..length - 1) { + for (index in 0 until length) { val element = get(index) if (predicate(element)) destination.append(element) } @@ -465,7 +465,7 @@ public inline fun String.takeLastWhile(predicate: (Char) -> Boolean): String { * Returns a subsequence of this char sequence containing the first characters that satisfy the given [predicate]. */ public inline fun CharSequence.takeWhile(predicate: (Char) -> Boolean): CharSequence { - for (index in 0..length - 1) + for (index in 0 until length) if (!predicate(get(index))) { return subSequence(0, index) } @@ -476,7 +476,7 @@ public inline fun CharSequence.takeWhile(predicate: (Char) -> Boolean): CharSequ * Returns a string containing the first characters that satisfy the given [predicate]. */ public inline fun String.takeWhile(predicate: (Char) -> Boolean): String { - for (index in 0..length - 1) + for (index in 0 until length) if (!predicate(get(index))) { return substring(0, index) } @@ -1321,7 +1321,7 @@ public infix fun CharSequence.zip(other: CharSequence): List> { public inline fun CharSequence.zip(other: CharSequence, transform: (a: Char, b: Char) -> V): List { val length = minOf(this.length, other.length) val list = ArrayList(length) - for (i in 0..length-1) { + for (i in 0 until length) { list.add(transform(this[i], other[i])) } return list @@ -1352,7 +1352,7 @@ public inline fun CharSequence.zipWithNext(transform: (a: Char, b: Char) -> val size = length - 1 if (size < 1) return emptyList() val result = ArrayList(size) - for (index in 0..size - 1) { + for (index in 0 until size) { result.add(transform(this[index], this[index + 1])) } return result diff --git a/libraries/stdlib/src/kotlin/collections/SlidingWindow.kt b/libraries/stdlib/src/kotlin/collections/SlidingWindow.kt index fc29541c35d..5296b7a8077 100644 --- a/libraries/stdlib/src/kotlin/collections/SlidingWindow.kt +++ b/libraries/stdlib/src/kotlin/collections/SlidingWindow.kt @@ -203,7 +203,7 @@ private class RingBuffer(val capacity: Int): AbstractList(), RandomAccess // TODO: replace with Array.fill from stdlib when available in common private fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int = size): Unit { - for (idx in fromIndex .. toIndex-1) { + for (idx in fromIndex until toIndex) { this[idx] = element } } diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index b8458b964ad..bb6a88ae784 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -703,7 +703,7 @@ internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence return false } - for (index in 0..length-1) { + for (index in 0 until length) { if (!this[thisOffset + index].equals(other[otherOffset + index], ignoreCase)) return false } @@ -1067,7 +1067,7 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v } else { val (index,length) = match - nextItem = currentStartIndex..index-1 + nextItem = currentStartIndex until index currentStartIndex = index + length nextSearchIndex = currentStartIndex + if (length == 0) 1 else 0 } diff --git a/libraries/stdlib/src/kotlin/text/regex/Regex.kt b/libraries/stdlib/src/kotlin/text/regex/Regex.kt index 32bdbaa20db..9a8a86cae10 100644 --- a/libraries/stdlib/src/kotlin/text/regex/Regex.kt +++ b/libraries/stdlib/src/kotlin/text/regex/Regex.kt @@ -281,5 +281,5 @@ private class MatcherMatchResult(private val matcher: Matcher, private val input } -private fun java.util.regex.MatchResult.range(): IntRange = start()..end()-1 -private fun java.util.regex.MatchResult.range(groupIndex: Int): IntRange = start(groupIndex)..end(groupIndex)-1 +private fun java.util.regex.MatchResult.range(): IntRange = start() until end() +private fun java.util.regex.MatchResult.range(groupIndex: Int): IntRange = start(groupIndex) until end(groupIndex) diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index a88e1ae6aa5..7b15609961e 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -128,7 +128,7 @@ public inline fun T.takeUnless(predicate: (T) -> Boolean): T? { public inline fun repeat(times: Int, action: (Int) -> Unit) { contract { callsInPlace(action) } - for (index in 0..times - 1) { + for (index in 0 until times) { action(index) } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt index 0098d5a9b7d..269dc7f0ef8 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Filtering.kt @@ -65,7 +65,7 @@ object Filtering : TemplateGroupBase() { list = ArrayList(resultSize) if (this is List) { if (this is RandomAccess) { - for (index in n..size - 1) + for (index in n until size) list.add(this[index]) } else { for (item in listIterator(n)) @@ -256,7 +256,7 @@ object Filtering : TemplateGroupBase() { if (n == 1) return listOf(this[size - 1]) val list = ArrayList(n) - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) return list """ @@ -271,7 +271,7 @@ object Filtering : TemplateGroupBase() { val list = ArrayList(n) if (this is RandomAccess) { - for (index in size - n .. size - 1) + for (index in size - n until size) list.add(this[index]) } else { for (item in listIterator(size - n)) @@ -364,7 +364,7 @@ object Filtering : TemplateGroupBase() { } body(Strings, CharSequences) { """ - for (index in 0..length - 1) + for (index in 0 until length) if (!predicate(get(index))) { return ${subsequence(f, "0", "index")} } @@ -422,7 +422,7 @@ object Filtering : TemplateGroupBase() { } body(CharSequences, Strings) { """ - for (index in this.indices.reversed()) + for (index in lastIndex downTo 0) if (!predicate(this[index])) return ${subsequence(f, "0", "index + 1")} @@ -537,7 +537,7 @@ object Filtering : TemplateGroupBase() { body(CharSequences) { """ - for (index in 0..length - 1) { + for (index in 0 until length) { val element = get(index) if (predicate(element)) destination.append(element) } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index c72211fb8bd..13ef48c2ae9 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -951,7 +951,7 @@ object Generators : TemplateGroupBase() { val size = ${if (f == CharSequences) "length" else "size" } - 1 if (size < 1) return emptyList() val result = ArrayList(size) - for (index in 0..size - 1) { + for (index in 0 until size) { result.add(transform(this[index], this[index + 1])) } return result @@ -1064,7 +1064,7 @@ object Generators : TemplateGroupBase() { """ val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -1088,7 +1088,7 @@ object Generators : TemplateGroupBase() { """ val size = minOf(size, other.size) val list = ArrayList(size) - for (i in 0..size-1) { + for (i in 0 until size) { list.add(transform(this[i], other[i])) } return list @@ -1131,7 +1131,7 @@ object Generators : TemplateGroupBase() { val length = minOf(this.length, other.length) val list = ArrayList(length) - for (i in 0..length-1) { + for (i in 0 until length) { list.add(transform(this[i], other[i])) } return list