Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline index extension properties #5350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions compiler/testData/ir/interpreter/helpers/Arrays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,46 @@ public actual fun DoubleArray.asList(): List<Double> = kotlin.UnsupportedOperati
public actual fun BooleanArray.asList(): List<Boolean> = kotlin.UnsupportedOperationException("This is intrinsic")
public actual fun CharArray.asList(): List<Char> = kotlin.UnsupportedOperationException("This is intrinsic")

public val <T> Array<out T>.indices: IntRange
public inline val <T> Array<out T>.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 <T> Array<out T>.isEmpty(): Boolean {
return size == 0
}

public val <T> Array<out T>.lastIndex: Int
public inline val <T> Array<out T>.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 {
Expand Down
4 changes: 2 additions & 2 deletions compiler/testData/ir/interpreter/helpers/Collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public inline fun <T> 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 <T> List<T>.lastIndex: Int
public inline val <T> List<T>.lastIndex: Int
get() = this.size - 1

public inline fun <T> Collection<T>.isNotEmpty(): Boolean = !isEmpty()
Expand Down
4 changes: 2 additions & 2 deletions compiler/testData/ir/interpreter/helpers/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 18 additions & 18 deletions libraries/stdlib/common/src/generated/_Arrays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> Array<out T>.indices: IntRange
public inline val <T> Array<out T>.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)

/**
Expand Down Expand Up @@ -7877,55 +7877,55 @@ public inline fun CharArray.isNotEmpty(): Boolean {
/**
* Returns the last valid index for the array.
*/
public val <T> Array<out T>.lastIndex: Int
public inline val <T> Array<out T>.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

/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/stdlib/src/kotlin/collections/Collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ internal expect inline fun <E> 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

/**
* Returns the index of the last item in the list or -1 if the list is empty.
*
* @sample samples.collections.Collections.Lists.lastIndexOfList
*/
public val <T> List<T>.lastIndex: Int
public inline val <T> List<T>.lastIndex: Int
get() = this.size - 1

/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/stdlib/src/kotlin/text/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ public inline fun <C, R> 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

/**
Expand Down