From f7436064d04932364775b5ca6f232142c908151e Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 2 Jul 2015 20:56:10 +0300 Subject: [PATCH] Unify componentN templates and add NOTHING_TO_INLINE suppression. --- libraries/stdlib/src/generated/_Elements.kt | 50 +++++++++++++++++++ .../src/templates/Elements.kt | 49 ++++++------------ 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/libraries/stdlib/src/generated/_Elements.kt b/libraries/stdlib/src/generated/_Elements.kt index 26a6543af20..e308581f8e1 100644 --- a/libraries/stdlib/src/generated/_Elements.kt +++ b/libraries/stdlib/src/generated/_Elements.kt @@ -13,6 +13,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") public inline fun Array.component1(): T { return get(0) } @@ -20,6 +21,7 @@ public inline fun Array.component1(): T { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun BooleanArray.component1(): Boolean { return get(0) } @@ -27,6 +29,7 @@ public inline fun BooleanArray.component1(): Boolean { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ByteArray.component1(): Byte { return get(0) } @@ -34,6 +37,7 @@ public inline fun ByteArray.component1(): Byte { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun CharArray.component1(): Char { return get(0) } @@ -41,6 +45,7 @@ public inline fun CharArray.component1(): Char { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun DoubleArray.component1(): Double { return get(0) } @@ -48,6 +53,7 @@ public inline fun DoubleArray.component1(): Double { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun FloatArray.component1(): Float { return get(0) } @@ -55,6 +61,7 @@ public inline fun FloatArray.component1(): Float { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun IntArray.component1(): Int { return get(0) } @@ -62,6 +69,7 @@ public inline fun IntArray.component1(): Int { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun LongArray.component1(): Long { return get(0) } @@ -69,6 +77,7 @@ public inline fun LongArray.component1(): Long { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ShortArray.component1(): Short { return get(0) } @@ -76,6 +85,7 @@ public inline fun ShortArray.component1(): Short { /** * Returns 1st *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun List.component1(): T { return get(0) } @@ -83,6 +93,7 @@ public inline fun List.component1(): T { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun Array.component2(): T { return get(1) } @@ -90,6 +101,7 @@ public inline fun Array.component2(): T { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun BooleanArray.component2(): Boolean { return get(1) } @@ -97,6 +109,7 @@ public inline fun BooleanArray.component2(): Boolean { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ByteArray.component2(): Byte { return get(1) } @@ -104,6 +117,7 @@ public inline fun ByteArray.component2(): Byte { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun CharArray.component2(): Char { return get(1) } @@ -111,6 +125,7 @@ public inline fun CharArray.component2(): Char { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun DoubleArray.component2(): Double { return get(1) } @@ -118,6 +133,7 @@ public inline fun DoubleArray.component2(): Double { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun FloatArray.component2(): Float { return get(1) } @@ -125,6 +141,7 @@ public inline fun FloatArray.component2(): Float { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun IntArray.component2(): Int { return get(1) } @@ -132,6 +149,7 @@ public inline fun IntArray.component2(): Int { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun LongArray.component2(): Long { return get(1) } @@ -139,6 +157,7 @@ public inline fun LongArray.component2(): Long { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ShortArray.component2(): Short { return get(1) } @@ -146,6 +165,7 @@ public inline fun ShortArray.component2(): Short { /** * Returns 2nd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun List.component2(): T { return get(1) } @@ -153,6 +173,7 @@ public inline fun List.component2(): T { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun Array.component3(): T { return get(2) } @@ -160,6 +181,7 @@ public inline fun Array.component3(): T { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun BooleanArray.component3(): Boolean { return get(2) } @@ -167,6 +189,7 @@ public inline fun BooleanArray.component3(): Boolean { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ByteArray.component3(): Byte { return get(2) } @@ -174,6 +197,7 @@ public inline fun ByteArray.component3(): Byte { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun CharArray.component3(): Char { return get(2) } @@ -181,6 +205,7 @@ public inline fun CharArray.component3(): Char { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun DoubleArray.component3(): Double { return get(2) } @@ -188,6 +213,7 @@ public inline fun DoubleArray.component3(): Double { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun FloatArray.component3(): Float { return get(2) } @@ -195,6 +221,7 @@ public inline fun FloatArray.component3(): Float { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun IntArray.component3(): Int { return get(2) } @@ -202,6 +229,7 @@ public inline fun IntArray.component3(): Int { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun LongArray.component3(): Long { return get(2) } @@ -209,6 +237,7 @@ public inline fun LongArray.component3(): Long { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ShortArray.component3(): Short { return get(2) } @@ -216,6 +245,7 @@ public inline fun ShortArray.component3(): Short { /** * Returns 3rd *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun List.component3(): T { return get(2) } @@ -223,6 +253,7 @@ public inline fun List.component3(): T { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun Array.component4(): T { return get(3) } @@ -230,6 +261,7 @@ public inline fun Array.component4(): T { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun BooleanArray.component4(): Boolean { return get(3) } @@ -237,6 +269,7 @@ public inline fun BooleanArray.component4(): Boolean { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ByteArray.component4(): Byte { return get(3) } @@ -244,6 +277,7 @@ public inline fun ByteArray.component4(): Byte { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun CharArray.component4(): Char { return get(3) } @@ -251,6 +285,7 @@ public inline fun CharArray.component4(): Char { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun DoubleArray.component4(): Double { return get(3) } @@ -258,6 +293,7 @@ public inline fun DoubleArray.component4(): Double { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun FloatArray.component4(): Float { return get(3) } @@ -265,6 +301,7 @@ public inline fun FloatArray.component4(): Float { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun IntArray.component4(): Int { return get(3) } @@ -272,6 +309,7 @@ public inline fun IntArray.component4(): Int { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun LongArray.component4(): Long { return get(3) } @@ -279,6 +317,7 @@ public inline fun LongArray.component4(): Long { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ShortArray.component4(): Short { return get(3) } @@ -286,6 +325,7 @@ public inline fun ShortArray.component4(): Short { /** * Returns 4th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun List.component4(): T { return get(3) } @@ -293,6 +333,7 @@ public inline fun List.component4(): T { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun Array.component5(): T { return get(4) } @@ -300,6 +341,7 @@ public inline fun Array.component5(): T { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun BooleanArray.component5(): Boolean { return get(4) } @@ -307,6 +349,7 @@ public inline fun BooleanArray.component5(): Boolean { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ByteArray.component5(): Byte { return get(4) } @@ -314,6 +357,7 @@ public inline fun ByteArray.component5(): Byte { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun CharArray.component5(): Char { return get(4) } @@ -321,6 +365,7 @@ public inline fun CharArray.component5(): Char { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun DoubleArray.component5(): Double { return get(4) } @@ -328,6 +373,7 @@ public inline fun DoubleArray.component5(): Double { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun FloatArray.component5(): Float { return get(4) } @@ -335,6 +381,7 @@ public inline fun FloatArray.component5(): Float { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun IntArray.component5(): Int { return get(4) } @@ -342,6 +389,7 @@ public inline fun IntArray.component5(): Int { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun LongArray.component5(): Long { return get(4) } @@ -349,6 +397,7 @@ public inline fun LongArray.component5(): Long { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun ShortArray.component5(): Short { return get(4) } @@ -356,6 +405,7 @@ public inline fun ShortArray.component5(): Short { /** * Returns 5th *element* from the collection. */ +suppress("NOTHING_TO_INLINE") public inline fun List.component5(): T { return get(4) } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index c05cfece09e..00a5bf4519b 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -704,40 +704,21 @@ fun elements(): List { } } - templates add f("component1()") { - inline(true) - doc { "Returns 1st *element* from the collection." } - returns("T") - body { "return get(0)" } - only(Lists, ArraysOfObjects, ArraysOfPrimitives) - } - templates add f("component2()") { - inline(true) - doc { "Returns 2nd *element* from the collection." } - returns("T") - body { "return get(1)" } - only(Lists, ArraysOfObjects, ArraysOfPrimitives) - } - templates add f("component3()") { - inline(true) - doc { "Returns 3rd *element* from the collection." } - returns("T") - body { "return get(2)" } - only(Lists, ArraysOfObjects, ArraysOfPrimitives) - } - templates add f("component4()") { - inline(true) - doc { "Returns 4th *element* from the collection." } - returns("T") - body { "return get(3)" } - only(Lists, ArraysOfObjects, ArraysOfPrimitives) - } - templates add f("component5()") { - inline(true) - doc { "Returns 5th *element* from the collection." } - returns("T") - body { "return get(4)" } - only(Lists, ArraysOfObjects, ArraysOfPrimitives) + templates addAll (1..5).map { n -> + f("component$n()") { + inline(true) + annotations("""suppress("NOTHING_TO_INLINE")""") + fun getOrdinal(n: Int) = n.toString() + when (n) { + 1 -> "st" + 2 -> "nd" + 3 -> "rd" + else -> "th" + } + doc { "Returns ${getOrdinal(n)} *element* from the collection." } + returns("T") + body { "return get(${n-1})" } + only(Lists, ArraysOfObjects, ArraysOfPrimitives) + } } return templates