Make overridden compareTo in unsigned types inline only

This commit is contained in:
Ilya Gorbunov
2018-09-18 17:43:10 +03:00
parent 9e0708e85a
commit af29dced98
7 changed files with 21 additions and 16 deletions
+5 -4
View File
@@ -100,11 +100,12 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/""")
if (otherType != type)
out.println(" @kotlin.internal.InlineOnly")
out.println(" @kotlin.internal.InlineOnly")
if (otherType == type)
out.println(""" @Suppress("OVERRIDE_BY_INLINE")""")
out.print(" public ")
if (otherType == type) out.print("override ") else out.print("inline ")
out.print("operator fun compareTo(other: ${otherType.capitalized}): Int = ")
if (otherType == type) out.print("override ")
out.print("inline operator fun compareTo(other: ${otherType.capitalized}): Int = ")
if (otherType == type && maxByDomainCapacity(type, UnsignedType.UINT) == type) {
out.println("${className.toLowerCase()}Compare(this.data, other.data)")
} else {
@@ -41,7 +41,9 @@ public inline class UByte @PublishedApi internal constructor(@PublishedApi inter
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt())
@kotlin.internal.InlineOnly
@Suppress("OVERRIDE_BY_INLINE")
public override inline operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
+3 -1
View File
@@ -57,7 +57,9 @@ public inline class UInt @PublishedApi internal constructor(@PublishedApi intern
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: UInt): Int = uintCompare(this.data, other.data)
@kotlin.internal.InlineOnly
@Suppress("OVERRIDE_BY_INLINE")
public override inline operator fun compareTo(other: UInt): Int = uintCompare(this.data, other.data)
/**
* Compares this value with the specified value for order.
@@ -65,7 +65,9 @@ public inline class ULong @PublishedApi internal constructor(@PublishedApi inter
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: ULong): Int = ulongCompare(this.data, other.data)
@kotlin.internal.InlineOnly
@Suppress("OVERRIDE_BY_INLINE")
public override inline operator fun compareTo(other: ULong): Int = ulongCompare(this.data, other.data)
/** Adds the other value to this value. */
@kotlin.internal.InlineOnly
@@ -49,7 +49,9 @@ public inline class UShort @PublishedApi internal constructor(@PublishedApi inte
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public override operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
@kotlin.internal.InlineOnly
@Suppress("OVERRIDE_BY_INLINE")
public override inline operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
@@ -6,7 +6,9 @@
@file:UseExperimental(ExperimentalUnsignedTypes::class)
package kotlin
@PublishedApi
internal fun uintCompare(v1: Int, v2: Int): Int = (v1 xor Int.MIN_VALUE).compareTo(v2 xor Int.MIN_VALUE)
@PublishedApi
internal fun ulongCompare(v1: Long, v2: Long): Int = (v1 xor Long.MIN_VALUE).compareTo(v2 xor Long.MIN_VALUE)
@PublishedApi
@@ -208,8 +208,6 @@ public final class kotlin/UByte : java/lang/Comparable {
public static final field SIZE_BYTES I
public static final synthetic fun box-impl (B)Lkotlin/UByte;
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun compareTo-7apg3OU (B)I
public static fun compareTo-7apg3OU (BB)I
public static fun constructor-impl (B)B
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (BLjava/lang/Object;)Z
@@ -270,8 +268,6 @@ public final class kotlin/UInt : java/lang/Comparable {
public static final field SIZE_BYTES I
public static final synthetic fun box-impl (I)Lkotlin/UInt;
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun compareTo-WZ4Q5Ns (I)I
public static fun compareTo-WZ4Q5Ns (II)I
public static fun constructor-impl (I)I
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (ILjava/lang/Object;)Z
@@ -332,8 +328,6 @@ public final class kotlin/ULong : java/lang/Comparable {
public static final field SIZE_BYTES I
public static final synthetic fun box-impl (J)Lkotlin/ULong;
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun compareTo-VKZWuLQ (J)I
public static fun compareTo-VKZWuLQ (JJ)I
public static fun constructor-impl (J)J
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (JLjava/lang/Object;)Z
@@ -394,8 +388,6 @@ public final class kotlin/UShort : java/lang/Comparable {
public static final field SIZE_BYTES I
public static final synthetic fun box-impl (S)Lkotlin/UShort;
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun compareTo-xj2QHRw (S)I
public static fun compareTo-xj2QHRw (SS)I
public static fun constructor-impl (S)S
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (SLjava/lang/Object;)Z
@@ -464,8 +456,10 @@ public abstract interface annotation class kotlin/UnsafeVariance : java/lang/ann
}
public final class kotlin/UnsignedKt {
public static final fun uintCompare (II)I
public static final fun uintDivide-J1ME1BU (II)I
public static final fun uintRemainder-J1ME1BU (II)I
public static final fun ulongCompare (JJ)I
public static final fun ulongDivide-eb3DHEI (JJ)J
public static final fun ulongRemainder-eb3DHEI (JJ)J
}