Make most of unsigned operations inline only
This commit is contained in:
@@ -12,7 +12,7 @@ import kotlin.experimental.*
|
||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public inline class UInt internal constructor(private val data: Int) : Comparable<UInt> {
|
||||
public inline class UInt @PublishedApi internal constructor(@PublishedApi internal val data: Int) : Comparable<UInt> {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
@@ -41,14 +41,16 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
|
||||
* 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: UByte): Int = this.compareTo(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun compareTo(other: UByte): Int = this.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: UShort): Int = this.compareTo(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun compareTo(other: UShort): Int = this.compareTo(other.toUInt())
|
||||
|
||||
/**
|
||||
* Compares this value with the specified value for order.
|
||||
@@ -62,83 +64,121 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
|
||||
* 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.plus(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun plus(other: UByte): UInt = this.plus(other.toUInt())
|
||||
/** Adds the other value to this value. */
|
||||
public operator fun plus(other: UShort): UInt = this.plus(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun plus(other: UShort): UInt = this.plus(other.toUInt())
|
||||
/** Adds the other value to this value. */
|
||||
public operator fun plus(other: UInt): UInt = UInt(this.data.plus(other.data))
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun plus(other: UInt): UInt = UInt(this.data.plus(other.data))
|
||||
/** 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.minus(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun minus(other: UByte): UInt = this.minus(other.toUInt())
|
||||
/** Subtracts the other value from this value. */
|
||||
public operator fun minus(other: UShort): UInt = this.minus(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun minus(other: UShort): UInt = this.minus(other.toUInt())
|
||||
/** Subtracts the other value from this value. */
|
||||
public operator fun minus(other: UInt): UInt = UInt(this.data.minus(other.data))
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun minus(other: UInt): UInt = UInt(this.data.minus(other.data))
|
||||
/** 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.times(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun times(other: UByte): UInt = this.times(other.toUInt())
|
||||
/** Multiplies this value by the other value. */
|
||||
public operator fun times(other: UShort): UInt = this.times(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun times(other: UShort): UInt = this.times(other.toUInt())
|
||||
/** Multiplies this value by the other value. */
|
||||
public operator fun times(other: UInt): UInt = UInt(this.data.times(other.data))
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun times(other: UInt): UInt = UInt(this.data.times(other.data))
|
||||
/** 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.div(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun div(other: UByte): UInt = this.div(other.toUInt())
|
||||
/** Divides this value by the other value. */
|
||||
public operator fun div(other: UShort): UInt = this.div(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun div(other: UShort): UInt = this.div(other.toUInt())
|
||||
/** Divides this value by the other value. */
|
||||
public operator fun div(other: UInt): UInt = uintDivide(this, other)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun div(other: UInt): UInt = uintDivide(this, 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.rem(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun rem(other: UByte): UInt = this.rem(other.toUInt())
|
||||
/** Calculates the remainder of dividing this value by the other value. */
|
||||
public operator fun rem(other: UShort): UInt = this.rem(other.toUInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun rem(other: UShort): UInt = this.rem(other.toUInt())
|
||||
/** Calculates the remainder of dividing this value by the other value. */
|
||||
public operator fun rem(other: UInt): UInt = uintRemainder(this, other)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun rem(other: UInt): UInt = uintRemainder(this, 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(): UInt = UInt(data.inc())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun inc(): UInt = UInt(data.inc())
|
||||
/** Decrements this value. */
|
||||
public operator fun dec(): UInt = UInt(data.dec())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun dec(): UInt = UInt(data.dec())
|
||||
|
||||
/** Creates a range from this value to the specified [other] value. */
|
||||
public operator fun rangeTo(other: UInt): UIntRange = UIntRange(this, other)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun rangeTo(other: UInt): UIntRange = UIntRange(this, other)
|
||||
|
||||
/** Shifts this value left by the [bitCount] number of bits. */
|
||||
public infix fun shl(bitCount: Int): UInt = UInt(data shl bitCount)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun shl(bitCount: Int): UInt = UInt(data shl bitCount)
|
||||
/** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */
|
||||
public infix fun shr(bitCount: Int): UInt = UInt(data ushr bitCount)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun shr(bitCount: Int): UInt = UInt(data ushr bitCount)
|
||||
/** Performs a bitwise AND operation between the two values. */
|
||||
public infix fun and(other: UInt): UInt = UInt(this.data and other.data)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun and(other: UInt): UInt = UInt(this.data and other.data)
|
||||
/** Performs a bitwise OR operation between the two values. */
|
||||
public infix fun or(other: UInt): UInt = UInt(this.data or other.data)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun or(other: UInt): UInt = UInt(this.data or other.data)
|
||||
/** Performs a bitwise XOR operation between the two values. */
|
||||
public infix fun xor(other: UInt): UInt = UInt(this.data xor other.data)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline infix fun xor(other: UInt): UInt = UInt(this.data xor other.data)
|
||||
/** Inverts the bits in this value. */
|
||||
public fun inv(): UInt = UInt(data.inv())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun inv(): UInt = UInt(data.inv())
|
||||
|
||||
public fun toByte(): Byte = data.toByte()
|
||||
public fun toShort(): Short = data.toShort()
|
||||
public fun toInt(): Int = data
|
||||
public fun toLong(): Long = data.toLong() and 0xFFFF_FFFF
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toByte(): Byte = data.toByte()
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toShort(): Short = data.toShort()
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toInt(): Int = data
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toLong(): Long = data.toLong() and 0xFFFF_FFFF
|
||||
|
||||
public fun toUByte(): UByte = data.toUByte()
|
||||
public fun toUShort(): UShort = data.toUShort()
|
||||
public fun toUInt(): UInt = this
|
||||
public fun toULong(): ULong = data.toULong() and 0xFFFF_FFFFu
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toUByte(): UByte = data.toUByte()
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toUShort(): UShort = data.toUShort()
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toUInt(): UInt = this
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toULong(): ULong = ULong(data.toLong() and 0xFFFF_FFFF)
|
||||
|
||||
public override fun toString(): String = toLong().toString()
|
||||
|
||||
@@ -146,13 +186,17 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Byte.toUInt(): UInt = UInt(this.toInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Byte.toUInt(): UInt = UInt(this.toInt())
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Short.toUInt(): UInt = UInt(this.toInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Short.toUInt(): UInt = UInt(this.toInt())
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Int.toUInt(): UInt = UInt(this)
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Int.toUInt(): UInt = UInt(this)
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Long.toUInt(): UInt = UInt(this.toInt())
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Long.toUInt(): UInt = UInt(this.toInt())
|
||||
|
||||
Reference in New Issue
Block a user