1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 04:50:26 +08:00

Use asSequence.joinToString

This commit is contained in:
Him188 2020-02-27 09:31:46 +08:00
parent 85ea4563a4
commit 6b45f99160
2 changed files with 3 additions and 15 deletions
mirai-core/src/commonMain/kotlin/net.mamoe.mirai

View File

@ -52,7 +52,7 @@ class ContactList<C : Contact>(@MiraiInternalAPI val delegate: LockFreeLinkedLis
return null
}
override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")
override fun toString(): String = delegate.asSequence().joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")
}
operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C {

View File

@ -15,18 +15,6 @@ import kotlinx.atomicfu.AtomicRef
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.loop
inline fun <E> LockFreeLinkedList<E>.joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "[",
postfix: CharSequence = "]",
transform: ((E) -> CharSequence) = { it.toString() }
): String = prefix.toString() + buildString {
this@joinToString.forEach {
append(transform(it))
append(separator)
}
}.dropLast(separator.length) + postfix
/**
* Collect all the elements into a [MutableList] then cast it as a [List]
*/
@ -215,7 +203,7 @@ open class LockFreeLinkedList<E> {
internal fun <E> LockFreeLinkedListNode<E>.compareAndSetNextNodeRef(expect: LockFreeLinkedListNode<E>, update: LockFreeLinkedListNode<E>) =
this.nextNodeRef.compareAndSet(expect, update)
override fun toString(): String = joinToString()
override fun toString(): String = asSequence().joinToString()
@Suppress("unused")
internal fun getLinkStructure(): String = buildString {
@ -754,7 +742,7 @@ internal open class Tail<E> : LockFreeLinkedListNode<E>(null, null) {
open class LockFreeLinkedListNode<E>(
nextNode: LockFreeLinkedListNode<E>?,
private var initialNodeValue: E?
private val initialNodeValue: E?
) {
/*
internal val id: Int = nextId()