Commit c3de96dd authored by Him188's avatar Him188

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

parent a0f39e61
...@@ -81,16 +81,19 @@ val ContactList<*>.idContentString: String ...@@ -81,16 +81,19 @@ val ContactList<*>.idContentString: String
) + "]" ) + "]"
@MiraiInternalAPI
operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C { operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C {
forEach { if (it.id == id) return it } forEach { if (it.id == id) return it }
throw NoSuchElementException("No such contact: $id") throw NoSuchElementException("No such contact: $id")
} }
@MiraiInternalAPI
fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: Long): C? { fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: Long): C? {
forEach { if (it.id == id) return it } forEach { if (it.id == id) return it }
return null return null
} }
@OptIn(MiraiInternalAPI::class)
@PlannedRemoval("1.0.0") @PlannedRemoval("1.0.0")
@Deprecated( @Deprecated(
"use firstOrNull from stdlib", "use firstOrNull from stdlib",
...@@ -102,6 +105,7 @@ inline fun <C : Contact> LockFreeLinkedList<C>.firstOrNull(filter: (C) -> Boolea ...@@ -102,6 +105,7 @@ inline fun <C : Contact> LockFreeLinkedList<C>.firstOrNull(filter: (C) -> Boolea
return null return null
} }
@OptIn(MiraiInternalAPI::class)
@PlannedRemoval("1.0.0") @PlannedRemoval("1.0.0")
@Deprecated( @Deprecated(
"use firstOrNull from stdlib", "use firstOrNull from stdlib",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:OptIn(MiraiInternalAPI::class)
package net.mamoe.mirai.event.internal package net.mamoe.mirai.event.internal
...@@ -122,6 +123,7 @@ internal object EventListenerManager { ...@@ -122,6 +123,7 @@ internal object EventListenerManager {
// 不要用 atomicfu. 在 publish 后会出现 VerifyError // 不要用 atomicfu. 在 publish 后会出现 VerifyError
private val lock: MiraiAtomicBoolean = MiraiAtomicBoolean(false) private val lock: MiraiAtomicBoolean = MiraiAtomicBoolean(false)
@OptIn(MiraiInternalAPI::class)
@Suppress("UNCHECKED_CAST", "BooleanLiteralArgument") @Suppress("UNCHECKED_CAST", "BooleanLiteralArgument")
internal tailrec fun <E : Event> get(clazz: KClass<out E>): EventListeners<E> { internal tailrec fun <E : Event> get(clazz: KClass<out E>): EventListeners<E> {
registries.forEach { registries.forEach {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:OptIn(MiraiInternalAPI::class)
package net.mamoe.mirai.message.data package net.mamoe.mirai.message.data
import kotlinx.io.core.* import kotlinx.io.core.*
...@@ -114,6 +115,7 @@ sealed class CustomMessage : SingleMessage { ...@@ -114,6 +115,7 @@ sealed class CustomMessage : SingleMessage {
override val typeName: String get() = "CustomMessage" override val typeName: String get() = "CustomMessage"
private val factories: LockFreeLinkedList<Factory<*>> = LockFreeLinkedList() private val factories: LockFreeLinkedList<Factory<*>> = LockFreeLinkedList()
@OptIn(MiraiInternalAPI::class)
internal fun register(factory: Factory<out CustomMessage>) { internal fun register(factory: Factory<out CustomMessage>) {
factories.removeIf { it::class == factory::class } factories.removeIf { it::class == factory::class }
val exist = factories.asSequence().firstOrNull { it.typeName == factory.typeName } val exist = factories.asSequence().firstOrNull { it.typeName == factory.typeName }
...@@ -134,6 +136,7 @@ sealed class CustomMessage : SingleMessage { ...@@ -134,6 +136,7 @@ sealed class CustomMessage : SingleMessage {
class CustomMessageFullDataDeserializeUserException(val body: ByteArray, cause: Throwable?) : class CustomMessageFullDataDeserializeUserException(val body: ByteArray, cause: Throwable?) :
RuntimeException(cause) RuntimeException(cause)
@OptIn(MiraiInternalAPI::class)
internal fun deserialize(fullData: ByteReadPacket): CustomMessage? { internal fun deserialize(fullData: ByteReadPacket): CustomMessage? {
val msg = kotlin.runCatching { val msg = kotlin.runCatching {
val length = fullData.readInt() val length = fullData.readInt()
......
...@@ -19,11 +19,13 @@ import kotlin.jvm.JvmOverloads ...@@ -19,11 +19,13 @@ import kotlin.jvm.JvmOverloads
/** /**
* Collect all the elements into a [MutableList] then cast it as a [List] * Collect all the elements into a [MutableList] then cast it as a [List]
*/ */
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toList(): List<E> = toMutableList() fun <E> LockFreeLinkedList<E>.toList(): List<E> = toMutableList()
/** /**
* Collect all the elements into a [MutableList]. * Collect all the elements into a [MutableList].
*/ */
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> { fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
val list = mutableListOf<E>() val list = mutableListOf<E>()
this.forEach { list.add(it) } this.forEach { list.add(it) }
...@@ -33,11 +35,13 @@ fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> { ...@@ -33,11 +35,13 @@ fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
/** /**
* Collect all the elements into a [MutableSet] then cast it as a [Set] * Collect all the elements into a [MutableSet] then cast it as a [Set]
*/ */
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toSet(): Set<E> = toMutableSet() fun <E> LockFreeLinkedList<E>.toSet(): Set<E> = toMutableSet()
/** /**
* Collect all the elements into a [MutableSet]. * Collect all the elements into a [MutableSet].
*/ */
@MiraiInternalAPI
fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> { fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> {
val list = mutableSetOf<E>() val list = mutableSetOf<E>()
this.forEach { list.add(it) } this.forEach { list.add(it) }
...@@ -49,6 +53,7 @@ fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> { ...@@ -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 * 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> { fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
return sequence { return sequence {
forEach { forEach {
...@@ -57,6 +62,7 @@ fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> { ...@@ -57,6 +62,7 @@ fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
} }
} }
@MiraiInternalAPI
operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> { operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> {
return asSequence().iterator() return asSequence().iterator()
} }
...@@ -64,6 +70,7 @@ operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> { ...@@ -64,6 +70,7 @@ operator fun <E> LockFreeLinkedList<E>.iterator(): Iterator<E> {
/** /**
* 构建链表结构然后转为 [LockFreeLinkedList] * 构建链表结构然后转为 [LockFreeLinkedList]
*/ */
@MiraiInternalAPI
fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> { fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) } return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) }
} }
...@@ -71,6 +78,7 @@ fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> { ...@@ -71,6 +78,7 @@ fun <E> Iterable<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
/** /**
* 构建链表结构然后转为 [LockFreeLinkedList] * 构建链表结构然后转为 [LockFreeLinkedList]
*/ */
@MiraiInternalAPI
fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> { fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) } return LockFreeLinkedList<E>().apply { addAll(this@toLockFreeLinkedList) }
} }
...@@ -81,6 +89,8 @@ fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> { ...@@ -81,6 +89,8 @@ fun <E> Sequence<E>.toLockFreeLinkedList(): LockFreeLinkedList<E> {
* Modifying can be performed concurrently. * Modifying can be performed concurrently.
* Iterating concurrency is guaranteed. * 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> { open class LockFreeLinkedList<E> {
@PublishedApi @PublishedApi
internal val tail: Tail<E> = Tail() internal val tail: Tail<E> = Tail()
......
@file:OptIn(MiraiInternalAPI::class)
package net.mamoe.mirai.event.internal package net.mamoe.mirai.event.internal
import net.mamoe.mirai.event.Event import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.Listener import net.mamoe.mirai.event.Listener
import net.mamoe.mirai.utils.LockFreeLinkedList import net.mamoe.mirai.utils.LockFreeLinkedList
import net.mamoe.mirai.utils.MiraiInternalAPI
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KClass import kotlin.reflect.KClass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment