From a1790a07163c4c04ab7df4f21975267e6e8f86f5 Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 24 Jun 2022 19:08:41 +0800 Subject: [PATCH] =?UTF-8?q?perf(config):=20=E4=BC=98=E5=8C=96=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BD=BF=E7=94=A8=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过调整部分属性的 null-safety 特性, 移除了部分 non-null 判断, 略微(真的很略微)提高了性能(虽然仅限于启动). --- scalabot-app/src/main/kotlin/AppMain.kt | 6 ++---- scalabot-meta/src/main/kotlin/Configs.kt | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scalabot-app/src/main/kotlin/AppMain.kt b/scalabot-app/src/main/kotlin/AppMain.kt index e5ba519..7146390 100644 --- a/scalabot-app/src/main/kotlin/AppMain.kt +++ b/scalabot-app/src/main/kotlin/AppMain.kt @@ -140,7 +140,7 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos log.info { "正在启动机器人 `${botConfig.account.name}`..." } val botOption = DefaultBotOptions().apply { val proxyConfig = - if (botConfig.proxy != null && botConfig.proxy!!.type != ProxyType.NO_PROXY) { + if (botConfig.proxy.type != ProxyType.NO_PROXY) { botConfig.proxy } else if (config.proxy.type != ProxyType.NO_PROXY) { config.proxy @@ -154,9 +154,7 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos log.debug { "机器人 `${botConfig.account.name}` 已启用代理配置: $proxyConfig" } } - if (botConfig.baseApiUrl != null) { - baseUrl = botConfig.baseApiUrl - } + baseUrl = botConfig.baseApiUrl } val account = botConfig.account diff --git a/scalabot-meta/src/main/kotlin/Configs.kt b/scalabot-meta/src/main/kotlin/Configs.kt index 28d02d4..60a335d 100644 --- a/scalabot-meta/src/main/kotlin/Configs.kt +++ b/scalabot-meta/src/main/kotlin/Configs.kt @@ -45,7 +45,7 @@ data class BotConfig( */ val extensions: Set = emptySet(), val proxy: ProxyConfig = ProxyConfig(type = ProxyType.NO_PROXY), - val baseApiUrl: String? = ApiConstants.BASE_URL + val baseApiUrl: String = ApiConstants.BASE_URL ) enum class ProxyType {