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() dTag.bytesUsedInMemory()
actual override fun compareTo(other: Address): Int { actual override fun compareTo(other: Address): Int {
val result = kind.compareTo(other.kind) val kindComparison = kind.compareTo(other.kind)
return if (result == 0) { return if (kindComparison == 0) {
val result2 = pubKeyHex.compareTo(other.pubKeyHex) val pubkeyComparison = pubKeyHex.compareTo(other.pubKeyHex)
if (result2 == 0) { if (pubkeyComparison == 0) {
dTag.compareTo(other.dTag) dTag.compareTo(other.dTag)
} else { } else {
result2 pubkeyComparison
} }
} else { } else {
result kindComparison
} }
} }

View File

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