Mark LockFreeLinkedList with MiraiInternalAPI, planning to make it internal in 1.0.0

This commit is contained in:
Him188 2020-04-27 22:07:27 +08:00
parent a0f39e61e6
commit c3de96dde0
5 changed files with 22 additions and 0 deletions

View File

@ -81,16 +81,19 @@ val ContactList<*>.idContentString: String
) + "]"
@MiraiInternalAPI
operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C {
forEach { if (it.id == id) return it }
throw NoSuchElementException("No such contact: $id")
}
@MiraiInternalAPI
fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: Long): C? {
forEach { if (it.id == id) return it }
return null
}
@OptIn(MiraiInternalAPI::class)
@PlannedRemoval("1.0.0")
@Deprecated(
"use firstOrNull from stdlib",
@ -102,6 +105,7 @@ inline fun <C : Contact> LockFreeLinkedList<C>.firstOrNull(filter: (C) -> Boolea
return null
}
@OptIn(MiraiInternalAPI::class)
@PlannedRemoval("1.0.0")
@Deprecated(
"use firstOrNull from stdlib",

View File

@ -6,6 +6,7 @@
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:OptIn(MiraiInternalAPI::class)
package net.mamoe.mirai.event.internal
@ -122,6 +123,7 @@ internal object EventListenerManager {
// 不要用 atomicfu. 在 publish 后会出现 VerifyError
private val lock: MiraiAtomicBoolean = MiraiAtomicBoolean(false)
@OptIn(MiraiInternalAPI::class)
@Suppress("UNCHECKED_CAST", "BooleanLiteralArgument")
internal tailrec fun <E : Event> get(clazz: KClass<out E>): EventListeners<E> {
registries.forEach {

View File

@ -7,6 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:OptIn(MiraiInternalAPI::class)
package net.mamoe.mirai.message.data
import kotlinx.io.core.*
@ -114,6 +115,7 @@ sealed class CustomMessage : SingleMessage {
override val typeName: String get() = "CustomMessage"
private val factories: LockFreeLinkedList<Factory<*>> = LockFreeLinkedList()
@OptIn(MiraiInternalAPI::class)
internal fun register(factory: Factory<out CustomMessage>) {
factories.removeIf { it::class == factory::class }
val exist = factories.asSequence().firstOrNull { it.typeName == factory.typeName }
@ -134,6 +136,7 @@ sealed class CustomMessage : SingleMessage {
class CustomMessageFullDataDeserializeUserException(val body: ByteArray, cause: Throwable?) :
RuntimeException(cause)
@OptIn(MiraiInternalAPI::class)
internal fun deserialize(fullData: ByteReadPacket): CustomMessage? {
val msg = kotlin.runCatching {
val length = fullData.readInt()

View File

@ -19,11 +19,13 @@ import kotlin.jvm.JvmOverloads
/**
* Collect all the elements into a [MutableList] then cast it as a [List]
*/
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toList(): List<E> = toMutableList()
/**
* Collect all the elements into a [MutableList].
*/
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
val list = mutableListOf<E>()
this.forEach { list.add(it) }
@ -33,11 +35,13 @@ fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
/**
* Collect all the elements into a [MutableSet] then cast it as a [Set]
*/
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toSet(): Set<E> = toMutableSet()
/**
* Collect all the elements into a [MutableSet].
*/
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> {
val list = mutableSetOf<E>()
this.forEach { list.add(it) }
@ -49,6 +53,7 @@ fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> {
*
* Note that the sequence is dynamic, that is, elements are yielded atomically only when it is required
*/
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
return sequence {
forEach {
@ -57,6 +62,7 @@ fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
}
}
@MiraiInternalAPI
operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> {
return asSequence().iterator()
}
@ -64,6 +70,7 @@ operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> {
/**
* 构建链表结构然后转为 [LockFreeLinkedList]
*/
@MiraiInternalAPI
fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) }
}
@ -71,6 +78,7 @@ fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
/**
* 构建链表结构然后转为 [LockFreeLinkedList]
*/
@MiraiInternalAPI
fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) }
}
@ -81,6 +89,8 @@ fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
* Modifying can be performed concurrently.
* Iterating concurrency is guaranteed.
*/
@PlannedRemoval("1.0.0") // make internal
@MiraiInternalAPI("This is unstable API and is going to be internal in 1.0.0")
open class LockFreeLinkedList<E> {
@PublishedApi
internal val tail: Tail<E> = Tail()

View File

@ -1,8 +1,11 @@
@file:OptIn(MiraiInternalAPI::class)
package net.mamoe.mirai.event.internal
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.Listener
import net.mamoe.mirai.utils.LockFreeLinkedList
import net.mamoe.mirai.utils.MiraiInternalAPI
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KClass