From a6e4a8d4fc691c6090c7af55d5d4df1c5317c4d1 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 6 Oct 2025 18:05:03 -0400 Subject: [PATCH] Performance improvement for the address serializer. --- .../vitorpamplona/quartz/nip01Core/core/Address.kt | 12 ++++++------ .../quartz/nip01Core/core/AddressSerializer.kt | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/Address.kt b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/Address.kt index 92eabead1..cbc23ae12 100644 --- a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/Address.kt +++ b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/Address.kt @@ -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 } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt index 0e3ec2490..ca60a06cd 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt @@ -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