From bb6a99f4adcfd83b90ce43ef127448cbf01fcbe8 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 29 Aug 2024 22:04:20 +0800 Subject: [PATCH] Inline index extension properties --- .../testData/ir/interpreter/helpers/Arrays.kt | 36 +++++++++---------- .../ir/interpreter/helpers/Collections.kt | 4 +-- .../ir/interpreter/helpers/Strings.kt | 4 +-- .../stdlib/common/src/generated/_Arrays.kt | 36 +++++++++---------- .../src/kotlin/collections/Collections.kt | 4 +-- libraries/stdlib/src/kotlin/text/Strings.kt | 4 +-- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/compiler/testData/ir/interpreter/helpers/Arrays.kt b/compiler/testData/ir/interpreter/helpers/Arrays.kt index 18ee99de59854..3b0799666bb21 100644 --- a/compiler/testData/ir/interpreter/helpers/Arrays.kt +++ b/compiler/testData/ir/interpreter/helpers/Arrays.kt @@ -100,46 +100,46 @@ public actual fun DoubleArray.asList(): List = kotlin.UnsupportedOperati public actual fun BooleanArray.asList(): List = kotlin.UnsupportedOperationException("This is intrinsic") public actual fun CharArray.asList(): List = kotlin.UnsupportedOperationException("This is intrinsic") -public val Array.indices: IntRange +public inline val Array.indices: IntRange get() = IntRange(0, lastIndex) -public val ByteArray.indices: IntRange +public inline val ByteArray.indices: IntRange get() = IntRange(0, lastIndex) -public val ShortArray.indices: IntRange +public inline val ShortArray.indices: IntRange get() = IntRange(0, lastIndex) -public val IntArray.indices: IntRange +public inline val IntArray.indices: IntRange get() = IntRange(0, lastIndex) -public val LongArray.indices: IntRange +public inline val LongArray.indices: IntRange get() = IntRange(0, lastIndex) -public val FloatArray.indices: IntRange +public inline val FloatArray.indices: IntRange get() = IntRange(0, lastIndex) -public val DoubleArray.indices: IntRange +public inline val DoubleArray.indices: IntRange get() = IntRange(0, lastIndex) -public val BooleanArray.indices: IntRange +public inline val BooleanArray.indices: IntRange get() = IntRange(0, lastIndex) -public val CharArray.indices: IntRange +public inline val CharArray.indices: IntRange get() = IntRange(0, lastIndex) public inline fun Array.isEmpty(): Boolean { return size == 0 } -public val Array.lastIndex: Int +public inline val Array.lastIndex: Int get() = size - 1 -public val ByteArray.lastIndex: Int +public inline val ByteArray.lastIndex: Int get() = size - 1 -public val ShortArray.lastIndex: Int +public inline val ShortArray.lastIndex: Int get() = size - 1 -public val IntArray.lastIndex: Int +public inline val IntArray.lastIndex: Int get() = size - 1 -public val LongArray.lastIndex: Int +public inline val LongArray.lastIndex: Int get() = size - 1 -public val FloatArray.lastIndex: Int +public inline val FloatArray.lastIndex: Int get() = size - 1 -public val DoubleArray.lastIndex: Int +public inline val DoubleArray.lastIndex: Int get() = size - 1 -public val BooleanArray.lastIndex: Int +public inline val BooleanArray.lastIndex: Int get() = size - 1 -public val CharArray.lastIndex: Int +public inline val CharArray.lastIndex: Int get() = size - 1 public fun ByteArray.first(): Int { diff --git a/compiler/testData/ir/interpreter/helpers/Collections.kt b/compiler/testData/ir/interpreter/helpers/Collections.kt index 3a3c4c02bce07..b9104e74dc06e 100644 --- a/compiler/testData/ir/interpreter/helpers/Collections.kt +++ b/compiler/testData/ir/interpreter/helpers/Collections.kt @@ -67,10 +67,10 @@ public inline fun MutableList(size: Int, init: (index: Int) -> T): MutableLi return list } -public val Collection<*>.indices: IntRange +public inline val Collection<*>.indices: IntRange get() = 0..size - 1 -public val List.lastIndex: Int +public inline val List.lastIndex: Int get() = this.size - 1 public inline fun Collection.isNotEmpty(): Boolean = !isEmpty() diff --git a/compiler/testData/ir/interpreter/helpers/Strings.kt b/compiler/testData/ir/interpreter/helpers/Strings.kt index 25fbec615943b..241a6450830de 100644 --- a/compiler/testData/ir/interpreter/helpers/Strings.kt +++ b/compiler/testData/ir/interpreter/helpers/Strings.kt @@ -50,10 +50,10 @@ public fun CharSequence.first(): Char { return this[0] } -public val CharSequence.indices: IntRange +public inline val CharSequence.indices: IntRange get() = 0..length - 1 -public val CharSequence.lastIndex: Int +public inline val CharSequence.lastIndex: Int get() = this.length - 1 public inline fun CharSequence.substring(startIndex: Int, endIndex: Int = length): String = subSequence(startIndex, endIndex).toString() diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 81efc65e42a0b..f6e7688292907 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -7679,55 +7679,55 @@ public expect fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int /** * Returns the range of valid indices for the array. */ -public val Array.indices: IntRange +public inline val Array.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val ByteArray.indices: IntRange +public inline val ByteArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val ShortArray.indices: IntRange +public inline val ShortArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val IntArray.indices: IntRange +public inline val IntArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val LongArray.indices: IntRange +public inline val LongArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val FloatArray.indices: IntRange +public inline val FloatArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val DoubleArray.indices: IntRange +public inline val DoubleArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val BooleanArray.indices: IntRange +public inline val BooleanArray.indices: IntRange get() = IntRange(0, lastIndex) /** * Returns the range of valid indices for the array. */ -public val CharArray.indices: IntRange +public inline val CharArray.indices: IntRange get() = IntRange(0, lastIndex) /** @@ -7877,55 +7877,55 @@ public inline fun CharArray.isNotEmpty(): Boolean { /** * Returns the last valid index for the array. */ -public val Array.lastIndex: Int +public inline val Array.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val ByteArray.lastIndex: Int +public inline val ByteArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val ShortArray.lastIndex: Int +public inline val ShortArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val IntArray.lastIndex: Int +public inline val IntArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val LongArray.lastIndex: Int +public inline val LongArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val FloatArray.lastIndex: Int +public inline val FloatArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val DoubleArray.lastIndex: Int +public inline val DoubleArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val BooleanArray.lastIndex: Int +public inline val BooleanArray.lastIndex: Int get() = size - 1 /** * Returns the last valid index for the array. */ -public val CharArray.lastIndex: Int +public inline val CharArray.lastIndex: Int get() = size - 1 /** diff --git a/libraries/stdlib/src/kotlin/collections/Collections.kt b/libraries/stdlib/src/kotlin/collections/Collections.kt index 6fbd1ea37dfe1..5241071eff562 100644 --- a/libraries/stdlib/src/kotlin/collections/Collections.kt +++ b/libraries/stdlib/src/kotlin/collections/Collections.kt @@ -224,7 +224,7 @@ internal expect inline fun buildListInternal(capacity: Int, builderAction: M * Returns an [IntRange] of the valid indices for this collection. * @sample samples.collections.Collections.Collections.indicesOfCollection */ -public val Collection<*>.indices: IntRange +public inline val Collection<*>.indices: IntRange get() = 0..size - 1 /** @@ -232,7 +232,7 @@ public val Collection<*>.indices: IntRange * * @sample samples.collections.Collections.Lists.lastIndexOfList */ -public val List.lastIndex: Int +public inline val List.lastIndex: Int get() = this.size - 1 /** diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 87cc1bf318861..722cabfda2352 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -381,13 +381,13 @@ public inline fun C.ifBlank(defaultValue: () -> R): R where C : CharSeque /** * Returns the range of valid character indices for this char sequence. */ -public val CharSequence.indices: IntRange +public inline val CharSequence.indices: IntRange get() = 0..length - 1 /** * Returns the index of the last character in the char sequence or -1 if it is empty. */ -public val CharSequence.lastIndex: Int +public inline val CharSequence.lastIndex: Int get() = this.length - 1 /**