mirror of
git://jb55.com/damus
synced 2024-10-04 19:00:42 +00:00
ndb: copy over perf improvements
This commit is contained in:
parent
e34351ca37
commit
99b5dc94cb
@ -28,7 +28,7 @@ final class NdbTests: XCTestCase {
|
||||
XCTAssertEqual(hex_encode(note.id), id)
|
||||
XCTAssertEqual(hex_encode(note.pubkey), pubkey)
|
||||
|
||||
XCTAssertEqual(note.count, 34058)
|
||||
XCTAssertEqual(note.count, 34322)
|
||||
XCTAssertEqual(note.kind, 3)
|
||||
XCTAssertEqual(note.created_at, 1689904312)
|
||||
|
||||
@ -82,19 +82,19 @@ final class NdbTests: XCTestCase {
|
||||
}
|
||||
|
||||
var count = 0
|
||||
var char_count = 0
|
||||
for tag in note.tags() {
|
||||
for elem in tag {
|
||||
print("iter_elem \(elem.string())")
|
||||
/*
|
||||
for _ in elem {
|
||||
count += 1
|
||||
for c in elem {
|
||||
char_count += 1
|
||||
}
|
||||
*/
|
||||
}
|
||||
count += 1
|
||||
}
|
||||
|
||||
XCTAssertEqual(count, 786)
|
||||
XCTAssertEqual(char_count, 24370)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ static inline int ndb_builder_find_str(struct ndb_builder *builder,
|
||||
uint32_t index = ((uint32_t*)builder->str_indices.start)[i];
|
||||
const char *some_str = (const char*)builder->strings.start + index;
|
||||
|
||||
if (!strncmp(some_str, str, len)) {
|
||||
if (!memcmp(some_str, str, len)) {
|
||||
// found an existing matching str, use that index
|
||||
*pstr = ndb_offset_str(index);
|
||||
return 1;
|
||||
@ -171,10 +171,13 @@ static int ndb_builder_push_packed_id(struct ndb_builder *builder,
|
||||
unsigned char *id,
|
||||
union ndb_packed_str *pstr)
|
||||
{
|
||||
if (ndb_builder_find_str(builder, (const char*)id, 32, pstr)) {
|
||||
pstr->packed.flag = NDB_PACKED_ID;
|
||||
return 1;
|
||||
}
|
||||
// Don't both find id duplicates. very rarely are they duplicated
|
||||
// and it slows things down quite a bit. If we really care about this
|
||||
// We can switch to a hash table.
|
||||
//if (ndb_builder_find_str(builder, (const char*)id, 32, pstr)) {
|
||||
// pstr->packed.flag = NDB_PACKED_ID;
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
if (ndb_builder_push_str(builder, (const char*)id, 32, pstr)) {
|
||||
pstr->packed.flag = NDB_PACKED_ID;
|
||||
|
Loading…
Reference in New Issue
Block a user