Inline-only in generated code

This commit is contained in:
Ilya Gorbunov
2016-01-27 21:27:54 +03:00
parent 8c0008aa2e
commit c7bd70732c
16 changed files with 350 additions and 175 deletions
File diff suppressed because it is too large Load Diff
+25 -13
View File
@@ -16,7 +16,7 @@ import java.util.Collections // TODO: it's temporary while we have java.util.Col
/**
* Returns 1st *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <T> List<T>.component1(): T {
return get(0)
}
@@ -24,7 +24,7 @@ public inline operator fun <T> List<T>.component1(): T {
/**
* Returns 2nd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <T> List<T>.component2(): T {
return get(1)
}
@@ -32,7 +32,7 @@ public inline operator fun <T> List<T>.component2(): T {
/**
* Returns 3rd *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <T> List<T>.component3(): T {
return get(2)
}
@@ -40,7 +40,7 @@ public inline operator fun <T> List<T>.component3(): T {
/**
* Returns 4th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <T> List<T>.component4(): T {
return get(3)
}
@@ -48,7 +48,7 @@ public inline operator fun <T> List<T>.component4(): T {
/**
* Returns 5th *element* from the collection.
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <T> List<T>.component5(): T {
return get(4)
}
@@ -74,7 +74,8 @@ public fun <T> Iterable<T>.elementAt(index: Int): T {
/**
* Returns an element at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this list.
*/
public fun <T> List<T>.elementAt(index: Int): T {
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.elementAt(index: Int): T {
return get(index)
}
@@ -99,6 +100,7 @@ public fun <T> Iterable<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T)
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this list.
*/
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
@@ -124,13 +126,15 @@ public fun <T> Iterable<T>.elementAtOrNull(index: Int): T? {
/**
* Returns an element at the given [index] or `null` if the [index] is out of bounds of this list.
*/
public fun <T> List<T>.elementAtOrNull(index: Int): T? {
return if (index >= 0 && index <= lastIndex) get(index) else null
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.elementAtOrNull(index: Int): T? {
return this.getOrNull(index)
}
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
return firstOrNull(predicate)
}
@@ -138,6 +142,7 @@ public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.findLast(predicate: (T) -> Boolean): T? {
return lastOrNull(predicate)
}
@@ -145,6 +150,7 @@ public inline fun <T> Iterable<T>.findLast(predicate: (T) -> Boolean): T? {
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.findLast(predicate: (T) -> Boolean): T? {
return lastOrNull(predicate)
}
@@ -227,6 +233,7 @@ public inline fun <T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean): T? {
/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this list.
*/
@kotlin.internal.InlineOnly
public inline fun <T> List<T>.getOrElse(index: Int, defaultValue: (Int) -> T): T {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
@@ -1320,7 +1327,8 @@ public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
/**
* Returns the number of elements in this collection.
*/
public fun <T> Collection<T>.count(): Int {
@kotlin.internal.InlineOnly
public inline fun <T> Collection<T>.count(): Int {
return size
}
@@ -1657,7 +1665,8 @@ public operator fun <T> Iterable<T>.minus(elements: Sequence<T>): List<T> {
/**
* Returns a list containing all elements of the original collection without the first occurrence of the given [element].
*/
public fun <T> Iterable<T>.minusElement(element: T): List<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.minusElement(element: T): List<T> {
return minus(element)
}
@@ -1771,14 +1780,16 @@ public operator fun <T> Iterable<T>.plus(elements: Sequence<T>): List<T> {
/**
* Returns a list containing all elements of the original collection and then the given [element].
*/
public fun <T> Collection<T>.plusElement(element: T): List<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Collection<T>.plusElement(element: T): List<T> {
return plus(element)
}
/**
* Returns a list containing all elements of the original collection and then the given [element].
*/
public fun <T> Iterable<T>.plusElement(element: T): List<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.plusElement(element: T): List<T> {
return plus(element)
}
@@ -1857,7 +1868,8 @@ public fun <T> Iterable<T>.joinToString(separator: CharSequence = ", ", prefix:
/**
* Returns this collection as an [Iterable].
*/
public fun <T> Iterable<T>.asIterable(): Iterable<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.asIterable(): Iterable<T> {
return this
}
+7 -3
View File
@@ -103,7 +103,8 @@ public inline fun <K, V> Map<K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean):
/**
* Returns the number of entries in this map.
*/
public fun <K, V> Map<K, V>.count(): Int {
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<K, V>.count(): Int {
return size
}
@@ -127,6 +128,7 @@ public inline fun <K, V> Map<K, V>.forEach(action: (Map.Entry<K, V>) -> Unit): U
/**
* Returns the first entry yielding the largest value of the given function or `null` if there are no entries.
*/
@kotlin.internal.InlineOnly
public inline fun <K, V, R : Comparable<R>> Map<K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
return entries.maxBy(selector)
}
@@ -134,7 +136,8 @@ public inline fun <K, V, R : Comparable<R>> Map<K, V>.maxBy(selector: (Map.Entry
/**
* Returns the first entry having the largest value according to the provided [comparator] or `null` if there are no entries.
*/
public fun <K, V> Map<K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<K, V>.maxWith(comparator: Comparator<in Map.Entry<K, V>>): Map.Entry<K, V>? {
return entries.maxWith(comparator)
}
@@ -171,7 +174,8 @@ public inline fun <K, V> Map<K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean)
/**
* Creates an [Iterable] instance that wraps the original map returning its entries when being iterated.
*/
public fun <K, V> Map<K, V>.asIterable(): Iterable<Map.Entry<K, V>> {
@kotlin.internal.InlineOnly
public inline fun <K, V> Map<K, V>.asIterable(): Iterable<Map.Entry<K, V>> {
return entries
}
+8 -3
View File
@@ -62,6 +62,7 @@ public fun <T> Sequence<T>.elementAtOrNull(index: Int): T? {
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>.find(predicate: (T) -> Boolean): T? {
return firstOrNull(predicate)
}
@@ -69,6 +70,7 @@ public inline fun <T> Sequence<T>.find(predicate: (T) -> Boolean): T? {
/**
* Returns the last element matching the given [predicate], or `null` if no such element was found.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>.findLast(predicate: (T) -> Boolean): T? {
return lastOrNull(predicate)
}
@@ -1053,7 +1055,8 @@ public operator fun <T> Sequence<T>.minus(elements: Sequence<T>): Sequence<T> {
/**
* Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
*/
public fun <T> Sequence<T>.minusElement(element: T): Sequence<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>.minusElement(element: T): Sequence<T> {
return minus(element)
}
@@ -1112,7 +1115,8 @@ public operator fun <T> Sequence<T>.plus(elements: Sequence<T>): Sequence<T> {
/**
* Returns a sequence containing all elements of the original sequence and then the given [element].
*/
public fun <T> Sequence<T>.plusElement(element: T): Sequence<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>.plusElement(element: T): Sequence<T> {
return plus(element)
}
@@ -1174,7 +1178,8 @@ public fun <T> Sequence<T>.asIterable(): Iterable<T> {
/**
* Returns this sequence as a [Sequence].
*/
public fun <T> Sequence<T>.asSequence(): Sequence<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Sequence<T>.asSequence(): Sequence<T> {
return this
}
+4 -2
View File
@@ -57,7 +57,8 @@ public operator fun <T> Set<T>.minus(elements: Sequence<T>): Set<T> {
/**
* Returns a set containing all elements of the original set except the given [element].
*/
public fun <T> Set<T>.minusElement(element: T): Set<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Set<T>.minusElement(element: T): Set<T> {
return minus(element)
}
@@ -104,7 +105,8 @@ public operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T> {
/**
* Returns a set containing all elements of the original set and then the given [element].
*/
public fun <T> Set<T>.plusElement(element: T): Set<T> {
@kotlin.internal.InlineOnly
public inline fun <T> Set<T>.plusElement(element: T): Set<T> {
return plus(element)
}
+17 -14
View File
@@ -16,13 +16,15 @@ import java.util.Collections // TODO: it's temporary while we have java.util.Col
/**
* Returns a character at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this char sequence.
*/
public fun CharSequence.elementAt(index: Int): Char {
@kotlin.internal.InlineOnly
public inline fun CharSequence.elementAt(index: Int): Char {
return get(index)
}
/**
* Returns a character at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this char sequence.
*/
@kotlin.internal.InlineOnly
public inline fun CharSequence.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
@@ -30,13 +32,15 @@ public inline fun CharSequence.elementAtOrElse(index: Int, defaultValue: (Int) -
/**
* Returns a character at the given [index] or `null` if the [index] is out of bounds of this char sequence.
*/
public fun CharSequence.elementAtOrNull(index: Int): Char? {
return if (index >= 0 && index <= lastIndex) get(index) else null
@kotlin.internal.InlineOnly
public inline fun CharSequence.elementAtOrNull(index: Int): Char? {
return this.getOrNull(index)
}
/**
* Returns the first character matching the given [predicate], or `null` if no such character was found.
*/
@kotlin.internal.InlineOnly
public inline fun CharSequence.find(predicate: (Char) -> Boolean): Char? {
return firstOrNull(predicate)
}
@@ -44,6 +48,7 @@ public inline fun CharSequence.find(predicate: (Char) -> Boolean): Char? {
/**
* Returns the last character matching the given [predicate], or `null` if no such character was found.
*/
@kotlin.internal.InlineOnly
public inline fun CharSequence.findLast(predicate: (Char) -> Boolean): Char? {
return lastOrNull(predicate)
}
@@ -85,6 +90,7 @@ public inline fun CharSequence.firstOrNull(predicate: (Char) -> Boolean): Char?
/**
* Returns a character at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this char sequence.
*/
@kotlin.internal.InlineOnly
public inline fun CharSequence.getOrElse(index: Int, defaultValue: (Int) -> Char): Char {
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
}
@@ -387,14 +393,9 @@ public fun CharSequence.slice(indices: Iterable<Int>): CharSequence {
/**
* Returns a string containing characters of the original string at specified [indices].
*/
public fun String.slice(indices: Iterable<Int>): String {
val size = indices.collectionSizeOrDefault(10)
if (size == 0) return ""
val result = StringBuilder(size)
for (i in indices) {
result.append(get(i))
}
return result.toString()
@kotlin.internal.InlineOnly
public inline fun String.slice(indices: Iterable<Int>): String {
return (this as CharSequence).slice(indices).toString()
}
/**
@@ -487,8 +488,9 @@ public fun CharSequence.reversed(): CharSequence {
/**
* Returns a string with characters in reversed order.
*/
public fun String.reversed(): String {
return StringBuilder(this).reverse().toString()
@kotlin.internal.InlineOnly
public inline fun String.reversed(): String {
return (this as CharSequence).reversed().toString()
}
/**
@@ -809,7 +811,8 @@ public inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean {
/**
* Returns the length of this char sequence.
*/
public fun CharSequence.count(): Int {
@kotlin.internal.InlineOnly
public inline fun CharSequence.count(): Int {
return length
}
@@ -145,7 +145,7 @@ public fun <@kotlin.internal.OnlyInputTypes K, V> MutableMap<out K, V>.remove(ke
* }
* ```
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <K, V> Map.Entry<K, V>.component1(): K = key
/**
@@ -157,7 +157,7 @@ public inline operator fun <K, V> Map.Entry<K, V>.component1(): K = key
* }
* ```
*/
@Suppress("NOTHING_TO_INLINE")
@kotlin.internal.InlineOnly
public inline operator fun <K, V> Map.Entry<K, V>.component2(): V = value
/**
@@ -94,15 +94,25 @@ public interface MatchResult {
@Suppress("NOTHING_TO_INLINE")
@kotlin.jvm.JvmVersion
public class Destructured internal constructor(public val match: MatchResult) {
@kotlin.internal.InlineOnly
public operator inline fun component1(): String = match.groupValues[1]
@kotlin.internal.InlineOnly
public operator inline fun component2(): String = match.groupValues[2]
@kotlin.internal.InlineOnly
public operator inline fun component3(): String = match.groupValues[3]
@kotlin.internal.InlineOnly
public operator inline fun component4(): String = match.groupValues[4]
@kotlin.internal.InlineOnly
public operator inline fun component5(): String = match.groupValues[5]
@kotlin.internal.InlineOnly
public operator inline fun component6(): String = match.groupValues[6]
@kotlin.internal.InlineOnly
public operator inline fun component7(): String = match.groupValues[7]
@kotlin.internal.InlineOnly
public operator inline fun component8(): String = match.groupValues[8]
@kotlin.internal.InlineOnly
public operator inline fun component9(): String = match.groupValues[9]
@kotlin.internal.InlineOnly
public operator inline fun component10(): String = match.groupValues[10]
/**
* Returns destructured group values as a list of strings.