Skip to content

Commit

Permalink
optimized id matching function
Browse files Browse the repository at this point in the history
doesn't need to create a copy of the id

Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Apr 25, 2024
1 parent 3bcf63f commit 2903f4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion damus/Util/InsertSort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions nostrdb/NdbNote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ class NdbNote: Encodable, Equatable, Hashable {
var id: NoteId {
.init(Data(bytes: ndb_note_id(note), count: 32))
}

var raw_note_id: UnsafeMutablePointer<UInt8> {
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))
Expand Down

0 comments on commit 2903f4b

Please sign in to comment.