From f9da72c1362cd72a4e1da52f6b3135c6b07c6386 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 8 Jun 2021 16:16:01 +0800 Subject: [PATCH] Convert `DEFAULT_BLACKLIST` to function and initialize the immutable set only once --- .../components/PacketLoggingStrategy.kt | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/components/PacketLoggingStrategy.kt b/mirai-core/src/commonMain/kotlin/network/components/PacketLoggingStrategy.kt index 405d44632..93df9fb38 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/PacketLoggingStrategy.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/PacketLoggingStrategy.kt @@ -36,7 +36,7 @@ internal interface PacketLoggingStrategy { internal class PacketLoggingStrategyImpl( private val bot: AbstractBot, - private val blacklist: Set = DEFAULT_BLACKLIST, + private val blacklist: Set = getDefaultBlacklist(), ) : PacketLoggingStrategy { override fun logSent(logger: MiraiLogger, outgoingPacket: OutgoingPacket) { if (outgoingPacket.commandName in blacklist) return @@ -83,24 +83,27 @@ internal class PacketLoggingStrategyImpl( } companion object { - val DEFAULT_BLACKLIST: Set - get() { - if (systemProp("mirai.debug.network.show.verbose.packets", false)) return emptySet() - return setOf( - // C2C event sync, too verbose to show. - "MessageSvc.PushNotify", - "MessageSvc.PbGetMsg", - "MessageSvc.PbDeleteMsg", + fun getDefaultBlacklist(): Set { + if (systemProp("mirai.debug.network.show.verbose.packets", false)) return emptySet() + return DEFAULT_BLACKLIST + } - // Group event sync, decoded as specific events, to optimize logs. - "OnlinePush.ReqPush", - "OnlinePush.RespPush", + private val DEFAULT_BLACKLIST: Set by lazy { + setOf( + // C2C event sync, too verbose to show. + "MessageSvc.PushNotify", + "MessageSvc.PbGetMsg", + "MessageSvc.PbDeleteMsg", - // Periodic heartbeat, showing them does not help anything. - "Heartbeat.Alive", - "StatSvc.SimpleGet", - ) - } + // Group event sync, decoded as specific events, to optimize logs. + "OnlinePush.ReqPush", + "OnlinePush.RespPush", + + // Periodic heartbeat, showing them does not help anything. + "Heartbeat.Alive", + "StatSvc.SimpleGet", + ) + } @JvmField var SHOW_PACKET_DETAILS = systemProp("mirai.debug.network.show.packet.details", false)