Make shortcuts inline

This commit is contained in:
Him188 2019-12-01 00:04:18 +08:00
parent bd291a7d61
commit 18cc687d78

View File

@ -3,8 +3,9 @@ package net.mamoe.mirai.utils.internal
/**
* 要求 [this] 最小为 [min].
*/
@Suppress("NOTHING_TO_INLINE")
@PublishedApi
internal fun Int.coerceAtLeastOrFail(min: Int): Int {
internal inline fun Int.coerceAtLeastOrFail(min: Int): Int {
require(this >= min)
return this
}
@ -12,8 +13,9 @@ internal fun Int.coerceAtLeastOrFail(min: Int): Int {
/**
* 要求 [this] 最小为 [min].
*/
@Suppress("NOTHING_TO_INLINE")
@PublishedApi
internal fun Long.coerceAtLeastOrFail(min: Long): Long {
internal inline fun Long.coerceAtLeastOrFail(min: Long): Long {
require(this >= min)
return this
}
@ -21,13 +23,15 @@ internal fun Long.coerceAtLeastOrFail(min: Long): Long {
/**
* 要求 [this] 最大为 [max].
*/
@Suppress("NOTHING_TO_INLINE")
@PublishedApi
internal fun Int.coerceAtMostOrFail(max: Int): Int =
internal inline fun Int.coerceAtMostOrFail(max: Int): Int =
if (this >= max) error("value is greater than its expected maximum value $max")
else this
@Suppress("NOTHING_TO_INLINE")
@PublishedApi
internal fun Long.coerceAtMostOrFail(max: Long): Long =
internal inline fun Long.coerceAtMostOrFail(max: Long): Long =
if (this >= max) error("value is greater than its expected maximum value $max")
else this