damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit b7b7d65612fb2f131ff70d2e1cd3b6b28dfb1868
parent d205be3e0a50f4c011793f278086a1fefb363aee
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 20 Jun 2023 16:07:40 +0200

perf: don't use string concat when calculing SeenEven hash

Profiler was complaining about this one

Diffstat:
Mdamus/Nostr/RelayPool.swift | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift @@ -18,11 +18,16 @@ struct QueuedRequest { let relay: String } +struct SeenEvent: Hashable { + let relay_id: String + let evid: String +} + class RelayPool { var relays: [Relay] = [] var handlers: [RelayHandler] = [] var request_queue: [QueuedRequest] = [] - var seen: Set<String> = Set() + var seen: Set<SeenEvent> = Set() var counts: [String: UInt64] = [:] private let network_monitor = NWPathMonitor() @@ -233,7 +238,7 @@ class RelayPool { func record_seen(relay_id: String, event: NostrConnectionEvent) { if case .nostr_event(let ev) = event { if case .event(_, let nev) = ev { - let k = relay_id + nev.id + let k = SeenEvent(relay_id: relay_id, evid: nev.id) if !seen.contains(k) { seen.insert(k) if counts[relay_id] == nil {