Commit 43cb22e0 authored by Him188's avatar Him188

Remove MutableContactList

parent c4b42a31
...@@ -106,11 +106,9 @@ internal class BotImpl @PublishedApi internal constructor( ...@@ -106,11 +106,9 @@ internal class BotImpl @PublishedApi internal constructor(
// endregion // endregion
// region contacts // region contacts
@UseExperimental(MiraiInternalAPI::class) override val groups: ContactList<Group> = ContactList(LockFreeLinkedList())
override val groups: ContactList<Group> = ContactList(MutableContactList())
@UseExperimental(MiraiInternalAPI::class) override val qqs: ContactList<QQ> = ContactList(LockFreeLinkedList())
override val qqs: ContactList<QQ> = ContactList(MutableContactList())
/** /**
* 线程安全地获取缓存的 QQ 对象. 若没有对应的缓存, 则会创建一个. * 线程安全地获取缓存的 QQ 对象. 若没有对应的缓存, 则会创建一个.
......
...@@ -12,7 +12,7 @@ import net.mamoe.mirai.utils.joinToString ...@@ -12,7 +12,7 @@ import net.mamoe.mirai.utils.joinToString
*/ */
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
@Suppress("unused") @Suppress("unused")
class ContactList<C : Contact>(@PublishedApi internal val delegate: MutableContactList<C>) { class ContactList<C : Contact>(@PublishedApi internal val delegate: LockFreeLinkedList<C>) {
/** /**
* ID 列表的字符串表示. * ID 列表的字符串表示.
* 如: * 如:
...@@ -35,22 +35,14 @@ class ContactList<C : Contact>(@PublishedApi internal val delegate: MutableConta ...@@ -35,22 +35,14 @@ class ContactList<C : Contact>(@PublishedApi internal val delegate: MutableConta
override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")") override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")
} }
/** operator fun <C : Contact> LockFreeLinkedList<C>.get(id: UInt): C {
* 可修改联系人列表. 只会在内部使用.
*/
@MiraiInternalAPI
class MutableContactList<C : Contact> : LockFreeLinkedList<C>() {
override fun toString(): String = joinToString(separator = ", ", prefix = "MutableContactList(", postfix = ")")
operator fun get(id: UInt): C {
forEach { if (it.id == id) return it } forEach { if (it.id == id) return it }
throw NoSuchElementException() throw NoSuchElementException()
} }
fun getOrNull(id: UInt): C? { fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: UInt): C? {
forEach { if (it.id == id) return it } forEach { if (it.id == id) return it }
return null return null
}
fun getOrAdd(id: UInt, supplier: () -> C): C = super.filteringGetOrAdd({it.id == id}, supplier)
} }
fun <C : Contact> LockFreeLinkedList<C>.getOrAdd(id: UInt, supplier: () -> C): C = filteringGetOrAdd({ it.id == id }, supplier)
...@@ -10,6 +10,7 @@ import net.mamoe.mirai.message.internal.toPacket ...@@ -10,6 +10,7 @@ import net.mamoe.mirai.message.internal.toPacket
import net.mamoe.mirai.network.BotNetworkHandler import net.mamoe.mirai.network.BotNetworkHandler
import net.mamoe.mirai.network.protocol.tim.TIMProtocol import net.mamoe.mirai.network.protocol.tim.TIMProtocol
import net.mamoe.mirai.network.protocol.tim.packet.* import net.mamoe.mirai.network.protocol.tim.packet.*
import net.mamoe.mirai.utils.LockFreeLinkedList
import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.io.* import net.mamoe.mirai.utils.io.*
import net.mamoe.mirai.withSession import net.mamoe.mirai.withSession
...@@ -54,7 +55,7 @@ internal data class RawGroupInfo( ...@@ -54,7 +55,7 @@ internal data class RawGroupInfo(
@Suppress("NOTHING_TO_INLINE") // this function it only executed in one place. @Suppress("NOTHING_TO_INLINE") // this function it only executed in one place.
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
inline fun parseBy(group: Group): GroupInfo = group.bot.withSession { inline fun parseBy(group: Group): GroupInfo = group.bot.withSession {
val memberList = MutableContactList<Member>() val memberList = LockFreeLinkedList<Member>()
members.forEach { entry: Map.Entry<UInt, MemberPermission> -> members.forEach { entry: Map.Entry<UInt, MemberPermission> ->
entry.key.qq().let { group.Member(it, entry.value, it.coroutineContext) } entry.key.qq().let { group.Member(it, entry.value, it.coroutineContext) }
} }
......
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