perf(config): 优化配置使用过程中的判断.

通过调整部分属性的 null-safety 特性, 移除了部分 non-null 判断, 略微(真的很略微)提高了性能(虽然仅限于启动).
This commit is contained in:
LamGC 2022-06-24 19:08:41 +08:00
parent b12758bd18
commit a1790a0716
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 3 additions and 5 deletions

View File

@ -140,7 +140,7 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos
log.info { "正在启动机器人 `${botConfig.account.name}`..." } log.info { "正在启动机器人 `${botConfig.account.name}`..." }
val botOption = DefaultBotOptions().apply { val botOption = DefaultBotOptions().apply {
val proxyConfig = val proxyConfig =
if (botConfig.proxy != null && botConfig.proxy!!.type != ProxyType.NO_PROXY) { if (botConfig.proxy.type != ProxyType.NO_PROXY) {
botConfig.proxy botConfig.proxy
} else if (config.proxy.type != ProxyType.NO_PROXY) { } else if (config.proxy.type != ProxyType.NO_PROXY) {
config.proxy config.proxy
@ -154,10 +154,8 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos
log.debug { "机器人 `${botConfig.account.name}` 已启用代理配置: $proxyConfig" } log.debug { "机器人 `${botConfig.account.name}` 已启用代理配置: $proxyConfig" }
} }
if (botConfig.baseApiUrl != null) {
baseUrl = botConfig.baseApiUrl baseUrl = botConfig.baseApiUrl
} }
}
val account = botConfig.account val account = botConfig.account
val remoteRepositories = config.mavenRepositories val remoteRepositories = config.mavenRepositories

View File

@ -45,7 +45,7 @@ data class BotConfig(
*/ */
val extensions: Set<Artifact> = emptySet(), val extensions: Set<Artifact> = emptySet(),
val proxy: ProxyConfig = ProxyConfig(type = ProxyType.NO_PROXY), val proxy: ProxyConfig = ProxyConfig(type = ProxyType.NO_PROXY),
val baseApiUrl: String? = ApiConstants.BASE_URL val baseApiUrl: String = ApiConstants.BASE_URL
) )
enum class ProxyType { enum class ProxyType {