From 208b3331cab907f261a58c0c63911d6cf0bb89c2 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 26 Feb 2024 15:42:02 -0800 Subject: [PATCH] optimized id matching function doesn't need to create a copy of the id Signed-off-by: William Casarin --- damus/Shared/Utilities/InsertSort.swift | 2 +- nostrdb/NdbNote.swift | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/damus/Shared/Utilities/InsertSort.swift b/damus/Shared/Utilities/InsertSort.swift index 46aed63c..869e5230 100644 --- a/damus/Shared/Utilities/InsertSort.swift +++ b/damus/Shared/Utilities/InsertSort.swift @@ -59,7 +59,7 @@ func insert_uniq_sorted_event(events: inout [NostrEvent], new_ev: NostrEvent, cm for event in events { // don't insert duplicate events - if new_ev.id == event.id { + if new_ev.id_matches(other: event) { return false } diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift index 17106e56..cdefab80 100644 --- a/nostrdb/NdbNote.swift +++ b/nostrdb/NdbNote.swift @@ -106,6 +106,14 @@ class NdbNote: Codable, Equatable, Hashable { var id: NoteId { .init(Data(bytes: ndb_note_id(note), count: 32)) } + + var raw_note_id: UnsafeMutablePointer { + ndb_note_id(note.ptr) + } + + func id_matches(other: NdbNote) -> Bool { + memcmp(self.raw_note_id, other.raw_note_id, 32) == 0 + } var sig: Signature { .init(Data(bytes: ndb_note_sig(note), count: 64))