mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-09 19:50:27 +08:00
Replace usage of List.replaceAll with Kotlin's
This commit is contained in:
parent
0529d7679b
commit
d3583162a5
@ -18,6 +18,7 @@ import net.mamoe.mirai.message.data.Image.Key.IMAGE_ID_REGEX
|
||||
import net.mamoe.mirai.message.data.Image.Key.IMAGE_RESOURCE_ID_REGEX_1
|
||||
import net.mamoe.mirai.message.data.Image.Key.IMAGE_RESOURCE_ID_REGEX_2
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
import net.mamoe.mirai.utils.replaceAllKotlin
|
||||
import kotlin.native.concurrent.SharedImmutable
|
||||
|
||||
// region image
|
||||
@ -128,7 +129,7 @@ internal fun constrainSingleMessagesImpl(sequence: Sequence<SingleMessage>): Lis
|
||||
if (singleMessage is ConstrainSingle) {
|
||||
val key = singleMessage.key.topmostKey
|
||||
val firstOccurrence = list.first { it != null && key.isInstance(it) } // may be singleMessage itself
|
||||
list.replaceAll {
|
||||
list.replaceAllKotlin {
|
||||
when {
|
||||
it == null -> null
|
||||
it === firstOccurrence -> singleMessage
|
||||
|
@ -157,3 +157,10 @@ public inline fun <R> runCatchingExceptions(block: () -> R): Result<R> {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
public inline fun <E> MutableList<E>.replaceAllKotlin(operator: (E) -> E) {
|
||||
val li: MutableListIterator<E> = this.listIterator()
|
||||
while (li.hasNext()) {
|
||||
li.set(operator(li.next()))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user