Make most of unsigned operations inline only

This commit is contained in:
Ilya Gorbunov
2018-09-17 20:24:30 +03:00
parent d793221a7b
commit 9e0708e85a
7 changed files with 387 additions and 373 deletions
+85 -43
View File
@@ -12,7 +12,7 @@ import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public inline class UByte internal constructor(private val data: Byte) : Comparable<UByte> {
public inline class UByte @PublishedApi internal constructor(@PublishedApi internal val data: Byte) : Comparable<UByte> {
companion object {
/**
@@ -48,93 +48,131 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
* 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 operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
* 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 operator fun compareTo(other: UInt): Int = this.toUInt().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UInt): Int = this.toUInt().compareTo(other)
/**
* Compares this value with the specified value for order.
* 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 operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
/** Adds the other value to this value. */
public operator fun plus(other: UByte): UInt = this.toUInt().plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UByte): UInt = this.toUInt().plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UShort): UInt = this.toUInt().plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UShort): UInt = this.toUInt().plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UInt): UInt = this.toUInt().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UInt): UInt = this.toUInt().plus(other)
/** Adds the other value to this value. */
public operator fun plus(other: ULong): ULong = this.toULong().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: ULong): ULong = this.toULong().plus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: UByte): UInt = this.toUInt().minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UByte): UInt = this.toUInt().minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UShort): UInt = this.toUInt().minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UShort): UInt = this.toUInt().minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UInt): UInt = this.toUInt().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UInt): UInt = this.toUInt().minus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: ULong): ULong = this.toULong().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: ULong): ULong = this.toULong().minus(other)
/** Multiplies this value by the other value. */
public operator fun times(other: UByte): UInt = this.toUInt().times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UByte): UInt = this.toUInt().times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UShort): UInt = this.toUInt().times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UShort): UInt = this.toUInt().times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UInt): UInt = this.toUInt().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: UInt): UInt = this.toUInt().times(other)
/** Multiplies this value by the other value. */
public operator fun times(other: ULong): ULong = this.toULong().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: ULong): ULong = this.toULong().times(other)
/** Divides this value by the other value. */
public operator fun div(other: UByte): UInt = this.toUInt().div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UByte): UInt = this.toUInt().div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UShort): UInt = this.toUInt().div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UShort): UInt = this.toUInt().div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UInt): UInt = this.toUInt().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: UInt): UInt = this.toUInt().div(other)
/** Divides this value by the other value. */
public operator fun div(other: ULong): ULong = this.toULong().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: ULong): ULong = this.toULong().div(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UByte): UInt = this.toUInt().rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UByte): UInt = this.toUInt().rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UShort): UInt = this.toUInt().rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UShort): UInt = this.toUInt().rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UInt): UInt = this.toUInt().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UInt): UInt = this.toUInt().rem(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: ULong): ULong = this.toULong().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** Increments this value. */
public operator fun inc(): UByte = UByte(data.inc())
@kotlin.internal.InlineOnly
public inline operator fun inc(): UByte = UByte(data.inc())
/** Decrements this value. */
public operator fun dec(): UByte = UByte(data.dec())
@kotlin.internal.InlineOnly
public inline operator fun dec(): UByte = UByte(data.dec())
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: UByte): UIntRange = UIntRange(this.toUInt(), other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rangeTo(other: UByte): UIntRange = UIntRange(this.toUInt(), other.toUInt())
/** Performs a bitwise AND operation between the two values. */
public infix fun and(other: UByte): UByte = UByte(this.data and other.data)
@kotlin.internal.InlineOnly
public inline infix fun and(other: UByte): UByte = UByte(this.data and other.data)
/** Performs a bitwise OR operation between the two values. */
public infix fun or(other: UByte): UByte = UByte(this.data or other.data)
@kotlin.internal.InlineOnly
public inline infix fun or(other: UByte): UByte = UByte(this.data or other.data)
/** Performs a bitwise XOR operation between the two values. */
public infix fun xor(other: UByte): UByte = UByte(this.data xor other.data)
@kotlin.internal.InlineOnly
public inline infix fun xor(other: UByte): UByte = UByte(this.data xor other.data)
/** Inverts the bits in this value. */
public fun inv(): UByte = UByte(data.inv())
@kotlin.internal.InlineOnly
public inline fun inv(): UByte = UByte(data.inv())
public fun toByte(): Byte = data
public fun toShort(): Short = data.toShort() and 0xFF
public fun toInt(): Int = data.toInt() and 0xFF
public fun toLong(): Long = data.toLong() and 0xFF
@kotlin.internal.InlineOnly
public inline fun toByte(): Byte = data
@kotlin.internal.InlineOnly
public inline fun toShort(): Short = data.toShort() and 0xFF
@kotlin.internal.InlineOnly
public inline fun toInt(): Int = data.toInt() and 0xFF
@kotlin.internal.InlineOnly
public inline fun toLong(): Long = data.toLong() and 0xFF
public fun toUByte(): UByte = this
public fun toUShort(): UShort = data.toUShort() and 0xFFu
public fun toUInt(): UInt = data.toUInt() and 0xFFu
public fun toULong(): ULong = data.toULong() and 0xFFu
@kotlin.internal.InlineOnly
public inline fun toUByte(): UByte = this
@kotlin.internal.InlineOnly
public inline fun toUShort(): UShort = UShort(data.toShort() and 0xFF)
@kotlin.internal.InlineOnly
public inline fun toUInt(): UInt = UInt(data.toInt() and 0xFF)
@kotlin.internal.InlineOnly
public inline fun toULong(): ULong = ULong(data.toLong() and 0xFF)
public override fun toString(): String = toInt().toString()
@@ -142,13 +180,17 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Byte.toUByte(): UByte = UByte(this)
@kotlin.internal.InlineOnly
public inline fun Byte.toUByte(): UByte = UByte(this)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Short.toUByte(): UByte = UByte(this.toByte())
@kotlin.internal.InlineOnly
public inline fun Short.toUByte(): UByte = UByte(this.toByte())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Int.toUByte(): UByte = UByte(this.toByte())
@kotlin.internal.InlineOnly
public inline fun Int.toUByte(): UByte = UByte(this.toByte())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Long.toUByte(): UByte = UByte(this.toByte())
@kotlin.internal.InlineOnly
public inline fun Long.toUByte(): UByte = UByte(this.toByte())