Skip to content

Commit 0481721

Browse files
Abduqodiri QurbonzodaSpace Team
Abduqodiri Qurbonzoda
authored and
Space Team
committed
Clean up redundant apiVersionIsAtLeast() checks #KT-72278
1 parent 3fcdaaa commit 0481721

File tree

5 files changed

+20
-137
lines changed

5 files changed

+20
-137
lines changed

libraries/stdlib/jvm/src/generated/_ArraysJvm.kt

+12-66
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,7 @@ public actual inline infix fun <T> Array<out T>.contentDeepEquals(other: Array<o
488488
@JvmName("contentDeepEqualsNullable")
489489
@kotlin.internal.InlineOnly
490490
public actual inline infix fun <T> Array<out T>?.contentDeepEquals(other: Array<out T>?): Boolean {
491-
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
492-
return contentDeepEqualsImpl(other)
493-
else
494-
return java.util.Arrays.deepEquals(this, other)
491+
return contentDeepEqualsImpl(other)
495492
}
496493

497494
/**
@@ -518,10 +515,7 @@ public actual inline fun <T> Array<out T>.contentDeepHashCode(): Int {
518515
@JvmName("contentDeepHashCodeNullable")
519516
@kotlin.internal.InlineOnly
520517
public actual inline fun <T> Array<out T>?.contentDeepHashCode(): Int {
521-
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
522-
return contentDeepHashCodeImpl()
523-
else
524-
return java.util.Arrays.deepHashCode(this)
518+
return contentDeepHashCodeImpl()
525519
}
526520

527521
/**
@@ -554,10 +548,7 @@ public actual inline fun <T> Array<out T>.contentDeepToString(): String {
554548
@JvmName("contentDeepToStringNullable")
555549
@kotlin.internal.InlineOnly
556550
public actual inline fun <T> Array<out T>?.contentDeepToString(): String {
557-
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
558-
return contentDeepToStringImpl()
559-
else
560-
return java.util.Arrays.deepToString(this)
551+
return contentDeepToStringImpl()
561552
}
562553

563554
/**
@@ -1345,12 +1336,7 @@ public actual inline fun <T> Array<T>.copyOf(newSize: Int): Array<T?> {
13451336
@JvmName("copyOfRangeInline")
13461337
@kotlin.internal.InlineOnly
13471338
public actual inline fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T> {
1348-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1349-
copyOfRangeImpl(fromIndex, toIndex)
1350-
} else {
1351-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1352-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1353-
}
1339+
return copyOfRangeImpl(fromIndex, toIndex)
13541340
}
13551341

13561342
/**
@@ -1365,12 +1351,7 @@ public actual inline fun <T> Array<T>.copyOfRange(fromIndex: Int, toIndex: Int):
13651351
@JvmName("copyOfRangeInline")
13661352
@kotlin.internal.InlineOnly
13671353
public actual inline fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray {
1368-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1369-
copyOfRangeImpl(fromIndex, toIndex)
1370-
} else {
1371-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1372-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1373-
}
1354+
return copyOfRangeImpl(fromIndex, toIndex)
13741355
}
13751356

13761357
/**
@@ -1385,12 +1366,7 @@ public actual inline fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): By
13851366
@JvmName("copyOfRangeInline")
13861367
@kotlin.internal.InlineOnly
13871368
public actual inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray {
1388-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1389-
copyOfRangeImpl(fromIndex, toIndex)
1390-
} else {
1391-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1392-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1393-
}
1369+
return copyOfRangeImpl(fromIndex, toIndex)
13941370
}
13951371

13961372
/**
@@ -1405,12 +1381,7 @@ public actual inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): S
14051381
@JvmName("copyOfRangeInline")
14061382
@kotlin.internal.InlineOnly
14071383
public actual inline fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray {
1408-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1409-
copyOfRangeImpl(fromIndex, toIndex)
1410-
} else {
1411-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1412-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1413-
}
1384+
return copyOfRangeImpl(fromIndex, toIndex)
14141385
}
14151386

14161387
/**
@@ -1425,12 +1396,7 @@ public actual inline fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): Int
14251396
@JvmName("copyOfRangeInline")
14261397
@kotlin.internal.InlineOnly
14271398
public actual inline fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray {
1428-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1429-
copyOfRangeImpl(fromIndex, toIndex)
1430-
} else {
1431-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1432-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1433-
}
1399+
return copyOfRangeImpl(fromIndex, toIndex)
14341400
}
14351401

14361402
/**
@@ -1445,12 +1411,7 @@ public actual inline fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): Lo
14451411
@JvmName("copyOfRangeInline")
14461412
@kotlin.internal.InlineOnly
14471413
public actual inline fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray {
1448-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1449-
copyOfRangeImpl(fromIndex, toIndex)
1450-
} else {
1451-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1452-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1453-
}
1414+
return copyOfRangeImpl(fromIndex, toIndex)
14541415
}
14551416

14561417
/**
@@ -1465,12 +1426,7 @@ public actual inline fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): F
14651426
@JvmName("copyOfRangeInline")
14661427
@kotlin.internal.InlineOnly
14671428
public actual inline fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray {
1468-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1469-
copyOfRangeImpl(fromIndex, toIndex)
1470-
} else {
1471-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1472-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1473-
}
1429+
return copyOfRangeImpl(fromIndex, toIndex)
14741430
}
14751431

14761432
/**
@@ -1485,12 +1441,7 @@ public actual inline fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int):
14851441
@JvmName("copyOfRangeInline")
14861442
@kotlin.internal.InlineOnly
14871443
public actual inline fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray {
1488-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1489-
copyOfRangeImpl(fromIndex, toIndex)
1490-
} else {
1491-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1492-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1493-
}
1444+
return copyOfRangeImpl(fromIndex, toIndex)
14941445
}
14951446

14961447
/**
@@ -1505,12 +1456,7 @@ public actual inline fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int):
15051456
@JvmName("copyOfRangeInline")
15061457
@kotlin.internal.InlineOnly
15071458
public actual inline fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray {
1508-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1509-
copyOfRangeImpl(fromIndex, toIndex)
1510-
} else {
1511-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: $toIndex, size: $size")
1512-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1513-
}
1459+
return copyOfRangeImpl(fromIndex, toIndex)
15141460
}
15151461

15161462
@SinceKotlin("1.3")

libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt

+2-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package kotlin.collections
1010

1111
import kotlin.collections.builders.ListBuilder
1212
import kotlin.internal.InlineOnly
13-
import kotlin.internal.apiVersionIsAtLeast
1413

1514
/**
1615
* Returns a new read-only list containing only the specified object [element].
@@ -108,10 +107,7 @@ internal actual fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array
108107
@InlineOnly
109108
internal actual inline fun checkIndexOverflow(index: Int): Int {
110109
if (index < 0) {
111-
if (apiVersionIsAtLeast(1, 3, 0))
112-
throwIndexOverflow()
113-
else
114-
throw ArithmeticException("Index overflow has happened.")
110+
throwIndexOverflow()
115111
}
116112
return index
117113
}
@@ -121,10 +117,7 @@ internal actual inline fun checkIndexOverflow(index: Int): Int {
121117
@InlineOnly
122118
internal actual inline fun checkCountOverflow(count: Int): Int {
123119
if (count < 0) {
124-
if (apiVersionIsAtLeast(1, 3, 0))
125-
throwCountOverflow()
126-
else
127-
throw ArithmeticException("Count overflow has happened.")
120+
throwCountOverflow()
128121
}
129122
return count
130123
}

libraries/stdlib/jvm/src/kotlin/io/Closeable.kt

+1-11
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@ public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
2929
exception = e
3030
throw e
3131
} finally {
32-
when {
33-
apiVersionIsAtLeast(1, 1, 0) -> this.closeFinally(exception)
34-
this == null -> {}
35-
exception == null -> close()
36-
else ->
37-
try {
38-
close()
39-
} catch (closeException: Throwable) {
40-
// cause.addSuppressed(closeException) // ignored here
41-
}
42-
}
32+
this.closeFinally(exception)
4333
}
4434
}
4535

libraries/stdlib/native-wasm/src/kotlin/collections/Collections.kt

-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public actual fun <T> Iterable<T>.shuffled(): List<T> = toMutableList().apply {
106106
@InlineOnly
107107
internal actual inline fun checkIndexOverflow(index: Int): Int {
108108
if (index < 0) {
109-
// TODO: api version check?
110109
throwIndexOverflow()
111110
}
112111
return index
@@ -117,7 +116,6 @@ internal actual inline fun checkIndexOverflow(index: Int): Int {
117116
@InlineOnly
118117
internal actual inline fun checkCountOverflow(count: Int): Int {
119118
if (count < 0) {
120-
// TODO: api version check?
121119
throwCountOverflow()
122120
}
123121
return count

libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt

+5-49
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,8 @@ object ArrayOps : TemplateGroupBase() {
244244
on(Platform.JVM) {
245245
inlineOnly()
246246
annotation("""@JvmName("contentDeepEqualsNullable")""")
247-
body {
248-
"""
249-
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
250-
return contentDeepEqualsImpl(other)
251-
else
252-
return java.util.Arrays.deepEquals(this, other)
253-
"""
254-
}
255-
}
256-
on(Platform.JS) {
257-
body { "return contentDeepEqualsImpl(other)" }
258-
}
259-
on(Platform.Native) {
260-
body { "return contentDeepEqualsImpl(other)" }
261247
}
248+
body { "return contentDeepEqualsImpl(other)" }
262249
}
263250

264251
val f_contentToString = fn("contentToString()") {
@@ -351,21 +338,8 @@ object ArrayOps : TemplateGroupBase() {
351338
on(Platform.JVM) {
352339
inlineOnly()
353340
annotation("""@JvmName("contentDeepToStringNullable")""")
354-
body {
355-
"""
356-
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
357-
return contentDeepToStringImpl()
358-
else
359-
return java.util.Arrays.deepToString(this)
360-
"""
361-
}
362-
}
363-
on(Platform.JS) {
364-
body { "return contentDeepToStringImpl()" }
365-
}
366-
on(Platform.Native) {
367-
body { "return contentDeepToStringImpl()" }
368341
}
342+
body { "return contentDeepToStringImpl()" }
369343
}
370344

371345
val f_contentHashCode = fn("contentHashCode()") {
@@ -456,21 +430,12 @@ object ArrayOps : TemplateGroupBase() {
456430
on(Platform.JVM) {
457431
inlineOnly()
458432
annotation("""@JvmName("contentDeepHashCodeNullable")""")
459-
body {
460-
"""
461-
if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0))
462-
return contentDeepHashCodeImpl()
463-
else
464-
return java.util.Arrays.deepHashCode(this)
465-
"""
466-
}
467433
}
434+
435+
body { "return contentDeepHashCodeImpl()" }
468436
on(Platform.JS) {
469437
body { "return contentDeepHashCodeInternal()" }
470438
}
471-
on(Platform.Native) {
472-
body { "return contentDeepHashCodeImpl()" }
473-
}
474439
}
475440

476441
val f_toPrimitiveArray = fn("toPrimitiveArray()") {
@@ -1005,16 +970,7 @@ object ArrayOps : TemplateGroupBase() {
1005970
on(Platform.JVM) {
1006971
annotation("""@JvmName("copyOfRangeInline")""")
1007972
inlineOnly()
1008-
body {
1009-
"""
1010-
return if (kotlin.internal.apiVersionIsAtLeast(1, 3, 0)) {
1011-
copyOfRangeImpl(fromIndex, toIndex)
1012-
} else {
1013-
if (toIndex > size) throw IndexOutOfBoundsException("toIndex: ${'$'}toIndex, size: ${'$'}size")
1014-
java.util.Arrays.copyOfRange(this, fromIndex, toIndex)
1015-
}
1016-
"""
1017-
}
973+
body { "return copyOfRangeImpl(fromIndex, toIndex)" }
1018974
}
1019975
on(Platform.Native) {
1020976
body {

0 commit comments

Comments
 (0)