Use lazy for SemVersion.toString

This commit is contained in:
Him188 2020-09-20 13:56:12 +08:00
parent ef4d259f60
commit 7a533d4667

View File

@ -188,9 +188,7 @@ public data class SemVersion internal constructor(
} }
@Transient @Transient
private var toString: String? = null // For cache. private val toString: String by lazy(LazyThreadSafetyMode.NONE) {
override fun toString(): String {
return toString ?: kotlin.run {
buildString { buildString {
mainVersion.joinTo(this, ".") mainVersion.joinTo(this, ".")
identifier?.let { identifier -> identifier?.let { identifier ->
@ -201,10 +199,11 @@ public data class SemVersion internal constructor(
append('+') append('+')
append(metadata) append(metadata)
} }
}.also { toString = it }
} }
} }
override fun toString(): String = toString
/** /**
* [SemVersion] 转为 Kotlin data class 风格的 [String] * [SemVersion] 转为 Kotlin data class 风格的 [String]
*/ */