damus

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

commit 2d44f2744be5cb53933b23f34811b04f857a94ae
parent 04e408bfea906bf3e2f422f4da8cad51e6ca180d
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 24 Jul 2023 13:08:18 -0700

ndb: switch to computed property for tags

this will allows us to change less code on the switchover

Diffstat:
Mdamus/ContentParsing.swift | 2+-
Mnostrdb/NdbNote.swift | 12++++++------
Mnostrdb/Test/NdbTests.swift | 12++++++------
3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/damus/ContentParsing.swift b/damus/ContentParsing.swift @@ -60,7 +60,7 @@ func parse_note_content_ndb(note: NdbNote) -> Blocks { while (i < bs.num_blocks) { let block = bs.blocks[i] - if let converted = convert_block_ndb(block, tags: note.tags()) { + if let converted = convert_block_ndb(block, tags: note.tags) { out.append(converted) } diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift @@ -84,8 +84,8 @@ class NdbNote { ndb_note_kind(note) } - func tags() -> TagsSequence { - return .init(note: self) + var tags: TagsSequence { + .init(note: self) } deinit { @@ -169,18 +169,18 @@ extension NdbNote { // TODO: References iterator public var referenced_ids: LazyFilterSequence<References> { - References.ids(tags: self.tags()) + References.ids(tags: self.tags) } public var referenced_pubkeys: LazyFilterSequence<References> { - References.pubkeys(tags: self.tags()) + References.pubkeys(tags: self.tags) } func event_refs(_ privkey: String?) -> [EventRef] { if let rs = _event_refs { return rs } - let refs = interpret_event_refs_ndb(blocks: self.blocks(privkey).blocks, tags: self.tags()) + let refs = interpret_event_refs_ndb(blocks: self.blocks(privkey).blocks, tags: self.tags) self._event_refs = refs return refs } @@ -271,7 +271,7 @@ extension NdbNote { // NDBTODO: id -> data public func references(id: String, key: AsciiCharacter) -> Bool { - for ref in References(tags: self.tags()) { + for ref in References(tags: self.tags) { if ref.key == key && ref.id.string() == id { return true } diff --git a/nostrdb/Test/NdbTests.swift b/nostrdb/Test/NdbTests.swift @@ -33,14 +33,14 @@ final class NdbTests: XCTestCase { XCTAssertEqual(note.created_at, 1689904312) let expected_count: UInt16 = 786 - XCTAssertEqual(note.tags().count, expected_count) - XCTAssertEqual(note.tags().reduce(0, { sum, _ in sum + 1 }), expected_count) + XCTAssertEqual(note.tags.count, expected_count) + XCTAssertEqual(note.tags.reduce(0, { sum, _ in sum + 1 }), expected_count) var tags = 0 var total_count_stored = 0 var total_count_iter = 0 //let tags = note.tags() - for tag in note.tags() { + for tag in note.tags { total_count_stored += Int(tag.count) if tags == 0 || tags == 1 || tags == 2 { @@ -111,7 +111,7 @@ final class NdbTests: XCTestCase { } self.measure(options: longer_iter()) { let blocks = note.blocks(nil).blocks - let xs = interpret_event_refs_ndb(blocks: blocks, tags: note.tags()) + let xs = interpret_event_refs_ndb(blocks: blocks, tags: note.tags) XCTAssertEqual(xs.count, 1) } } @@ -135,7 +135,7 @@ final class NdbTests: XCTestCase { XCTAssertEqual(ev_blocks, note_blocks) let event_refs = interpret_event_refs(blocks: ev_blocks.blocks, tags: event.tags) - let note_refs = interpret_event_refs_ndb(blocks: note_blocks.blocks, tags: note.tags()) + let note_refs = interpret_event_refs_ndb(blocks: note_blocks.blocks, tags: note.tags) XCTAssertEqual(event_refs, note_refs) } @@ -151,7 +151,7 @@ final class NdbTests: XCTestCase { var count = 0 var char_count = 0 - for tag in note.tags() { + for tag in note.tags { for elem in tag { print("iter_elem \(elem.string())") for c in elem {