Performance improvement for the address serializer.

This commit is contained in:
Vitor Pamplona
2025-10-06 18:05:03 -04:00
parent 5f59f1ab41
commit a6e4a8d4fc
2 changed files with 13 additions and 7 deletions

View File

@@ -40,16 +40,16 @@ actual data class Address actual constructor(
dTag.bytesUsedInMemory()
actual override fun compareTo(other: Address): Int {
val result = kind.compareTo(other.kind)
return if (result == 0) {
val result2 = pubKeyHex.compareTo(other.pubKeyHex)
if (result2 == 0) {
val kindComparison = kind.compareTo(other.kind)
return if (kindComparison == 0) {
val pubkeyComparison = pubKeyHex.compareTo(other.pubKeyHex)
if (pubkeyComparison == 0) {
dTag.compareTo(other.dTag)
} else {
result2
pubkeyComparison
}
} else {
result
kindComparison
}
}

View File

@@ -31,7 +31,13 @@ class AddressSerializer {
kind: Int,
pubKeyHex: HexKey,
dTag: String = "",
) = "$kind:$pubKeyHex:$dTag"
) = buildString {
append(kind)
append(":")
append(pubKeyHex)
append(":")
append(dTag)
}
fun parse(addressId: String): Address? {
if (addressId.isBlank()) return null