mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-02 12:50:16 +08:00
Improve MessageChainBuilder
This commit is contained in:
parent
1e55d15047
commit
a992b61261
@ -170,20 +170,18 @@ public class MessageChainBuilder private constructor(
|
|||||||
|
|
||||||
///////
|
///////
|
||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
private var cache: StringBuilder? = null
|
private val cache: StringBuilder = StringBuilder()
|
||||||
private fun flushCache() {
|
private fun flushCache() {
|
||||||
cache?.let {
|
if (cache.isNotEmpty()) {
|
||||||
container.add(PlainText(it.toString()))
|
container.add(PlainText(cache.toString()))
|
||||||
|
cache.setLength(0)
|
||||||
}
|
}
|
||||||
cache = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun withCache(block: StringBuilder.() -> Unit): MessageChainBuilder {
|
private inline fun withCache(block: StringBuilder.() -> Unit): MessageChainBuilder {
|
||||||
if (cache == null) {
|
contract { callsInPlace(block, EXACTLY_ONCE) }
|
||||||
cache = StringBuilder().apply(block)
|
|
||||||
} else {
|
cache.apply(block)
|
||||||
cache!!.apply(block)
|
|
||||||
}
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user