Simplify comparisons for small unsigned types that can fit in Int

UByte and UShort can be extended to Int exactly and then compared as ints
This commit is contained in:
Ilya Gorbunov
2018-09-18 17:57:18 +03:00
parent af29dced98
commit 1d7ee22bdc
3 changed files with 10 additions and 6 deletions
@@ -43,7 +43,7 @@ public inline class UByte @PublishedApi internal constructor(@PublishedApi inter
*/
@kotlin.internal.InlineOnly
@Suppress("OVERRIDE_BY_INLINE")
public override inline operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt())
public override inline operator fun compareTo(other: UByte): Int = this.toInt().compareTo(other.toInt())
/**
* Compares this value with the specified value for order.
@@ -51,7 +51,7 @@ public inline class UByte @PublishedApi internal constructor(@PublishedApi inter
* or a positive number if it's greater than other.
*/
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
public inline operator fun compareTo(other: UShort): Int = this.toInt().compareTo(other.toInt())
/**
* Compares this value with the specified value for order.
@@ -42,7 +42,7 @@ public inline class UShort @PublishedApi internal constructor(@PublishedApi inte
* or a positive number if it's greater than other.
*/
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt())
public inline operator fun compareTo(other: UByte): Int = this.toInt().compareTo(other.toInt())
/**
* Compares this value with the specified value for order.
@@ -51,7 +51,7 @@ public inline class UShort @PublishedApi internal constructor(@PublishedApi inte
*/
@kotlin.internal.InlineOnly
@Suppress("OVERRIDE_BY_INLINE")
public override inline operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
public override inline operator fun compareTo(other: UShort): Int = this.toInt().compareTo(other.toInt())
/**
* Compares this value with the specified value for order.