diff --git a/libraries/stdlib/js/irRuntime/noPackageHacks.kt b/libraries/stdlib/js/irRuntime/noPackageHacks.kt index 0c422a023c9..42cf8360adc 100644 --- a/libraries/stdlib/js/irRuntime/noPackageHacks.kt +++ b/libraries/stdlib/js/irRuntime/noPackageHacks.kt @@ -9,7 +9,7 @@ internal fun arrayConcat(vararg args: T): T { val len = args.size val typed = js("Array(len)").unsafeCast>() - for (i in 0 until len) { + for (i in 0 .. (len - 1)) { val arr = args[i] if (arr !is Array<*>) { typed[i] = js("[]").slice.call(arr) @@ -25,7 +25,7 @@ internal fun arrayConcat(vararg args: T): T { @PublishedApi internal fun primitiveArrayConcat(vararg args: T): T { var size = 0 - for (i in 0 until args.size) { + for (i in 0 .. (args.size - 1)) { size += args[i].unsafeCast>().size } val a = args[0] @@ -35,9 +35,9 @@ internal fun primitiveArrayConcat(vararg args: T): T { } size = 0 - for (i in 0 until args.size) { + for (i in 0 .. (args.size - 1)) { val arr = args[i].unsafeCast>() - for (j in 0 until arr.size) { + for (j in 0 .. (arr.size - 1)) { result[size++] = arr[j] } } diff --git a/libraries/stdlib/js/irRuntime/rangeExtensions.kt b/libraries/stdlib/js/irRuntime/rangeExtensions.kt deleted file mode 100644 index fdf7681ca38..00000000000 --- a/libraries/stdlib/js/irRuntime/rangeExtensions.kt +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package kotlin.ranges - -// FIXME: Use stdlib _Ranges.kt instead - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Int.downTo(to: Byte): IntProgression { - return IntProgression.fromClosedRange(this, to.toInt(), -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Long.downTo(to: Byte): LongProgression { - return LongProgression.fromClosedRange(this, to.toLong(), -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Byte.downTo(to: Byte): IntProgression { - return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Short.downTo(to: Byte): IntProgression { - return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Char.downTo(to: Char): CharProgression { - return CharProgression.fromClosedRange(this, to, -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Int.downTo(to: Int): IntProgression { - return IntProgression.fromClosedRange(this, to, -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Long.downTo(to: Int): LongProgression { - return LongProgression.fromClosedRange(this, to.toLong(), -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Byte.downTo(to: Int): IntProgression { - return IntProgression.fromClosedRange(this.toInt(), to, -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Short.downTo(to: Int): IntProgression { - return IntProgression.fromClosedRange(this.toInt(), to, -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Int.downTo(to: Long): LongProgression { - return LongProgression.fromClosedRange(this.toLong(), to, -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Long.downTo(to: Long): LongProgression { - return LongProgression.fromClosedRange(this, to, -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Byte.downTo(to: Long): LongProgression { - return LongProgression.fromClosedRange(this.toLong(), to, -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Short.downTo(to: Long): LongProgression { - return LongProgression.fromClosedRange(this.toLong(), to, -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Int.downTo(to: Short): IntProgression { - return IntProgression.fromClosedRange(this, to.toInt(), -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Long.downTo(to: Short): LongProgression { - return LongProgression.fromClosedRange(this, to.toLong(), -1L) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Byte.downTo(to: Short): IntProgression { - return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) -} - -/** - * Returns a progression from this value down to the specified [to] value with the step -1. - * - * The [to] value should be less than or equal to `this` value. - * If the [to] value is greater than `this` value the returned progression is empty. - */ -public infix fun Short.downTo(to: Short): IntProgression { - return IntProgression.fromClosedRange(this.toInt(), to.toInt(), -1) -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Int.until(to: Byte): IntRange { - return this .. (to.toInt() - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Long.until(to: Byte): LongRange { - return this .. (to.toLong() - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Byte.until(to: Byte): IntRange { - return this.toInt() .. (to.toInt() - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Short.until(to: Byte): IntRange { - return this.toInt() .. (to.toInt() - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to `'\u0000'` the returned range is empty. - */ -public infix fun Char.until(to: Char): CharRange { - if (to <= '\u0000') return CharRange.EMPTY - return this .. (to - 1).toChar() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty. - */ -public infix fun Int.until(to: Int): IntRange { - if (to <= Int.MIN_VALUE) return IntRange.EMPTY - return this .. (to - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Long.until(to: Int): LongRange { - return this .. (to.toLong() - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty. - */ -public infix fun Byte.until(to: Int): IntRange { - if (to <= Int.MIN_VALUE) return IntRange.EMPTY - return this.toInt() .. (to - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty. - */ -public infix fun Short.until(to: Int): IntRange { - if (to <= Int.MIN_VALUE) return IntRange.EMPTY - return this.toInt() .. (to - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty. - */ -public infix fun Int.until(to: Long): LongRange { - if (to <= Long.MIN_VALUE) return LongRange.EMPTY - return this.toLong() .. (to - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty. - */ -public infix fun Long.until(to: Long): LongRange { - if (to <= Long.MIN_VALUE) return LongRange.EMPTY - return this .. (to - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty. - */ -public infix fun Byte.until(to: Long): LongRange { - if (to <= Long.MIN_VALUE) return LongRange.EMPTY - return this.toLong() .. (to - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - * - * If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty. - */ -public infix fun Short.until(to: Long): LongRange { - if (to <= Long.MIN_VALUE) return LongRange.EMPTY - return this.toLong() .. (to - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Int.until(to: Short): IntRange { - return this .. (to.toInt() - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Long.until(to: Short): LongRange { - return this .. (to.toLong() - 1).toLong() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Byte.until(to: Short): IntRange { - return this.toInt() .. (to.toInt() - 1).toInt() -} - -/** - * Returns a range from this value up to but excluding the specified [to] value. - * - * If the [to] value is less than or equal to `this` value the returned range is empty. - */ -public infix fun Short.until(to: Short): IntRange { - return this.toInt() .. (to.toInt() - 1).toInt() -} diff --git a/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt b/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt index ce48f06f6b8..32429a8e92b 100644 --- a/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt +++ b/libraries/stdlib/src/kotlin/coroutines/CoroutineContextImpl.kt @@ -98,7 +98,7 @@ internal class CombinedContext( override fun toString(): String = "[" + fold("") { acc, element -> - if (acc.isEmpty()) element.toString() else "$acc, $element" + if (acc.length == 0) element.toString() else "$acc, $element" } + "]" private fun writeReplace(): Any { @@ -116,6 +116,11 @@ internal class CombinedContext( private const val serialVersionUID: Long = 0L } - private fun readResolve(): Any = elements.fold(EmptyCoroutineContext, CoroutineContext::plus) + private fun readResolve(): Any { + var result: CoroutineContext = EmptyCoroutineContext + for (element in elements) + result = result + element + return result + } } } diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index aa3acb3c8b5..90cad8d4b00 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -135,7 +135,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 until times) { + for (index in 0 .. (times - 1)) { action(index) } }