Optimise SnodeAPI further

This commit is contained in:
bemusementpark
2024-08-03 21:19:31 +09:30
parent c1d40cdbe7
commit 3c8302f7a4
2 changed files with 8 additions and 9 deletions

View File

@@ -52,6 +52,8 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val v
fun Version(value: String) = CACHE.getOrElse(value) {
Snode.Version(value)
}
fun Version(parts: List<Int>) = Version(parts.joinToString("."))
}
@JvmInline
@@ -66,14 +68,12 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val v
}
}
constructor(parts: List<Int>): this(
internal constructor(parts: List<Int>): this(
parts.asSequence()
.map { it.toByte().toULong() }
.foldToVersionAsULong()
)
constructor(value: Int): this(value.toULong())
internal constructor(value: String): this(
value.splitToSequence(".")
.map { it.toULongOrNull() ?: 0UL }