summaryrefslogtreecommitdiff
path: root/src/packet_storage.c
diff options
context:
space:
mode:
authorGravatar moon <moon@coffin.ir> 2025-09-15 03:31:41 +0330
committerGravatar moon <moon@coffin.ir> 2025-09-15 03:31:41 +0330
commit53d387e60bbc69480737c84b6f09a9ca2b76aeea (patch)
treeeb75b700a8672037539c30cef254a4deedb6155f /src/packet_storage.c
parentlogging (diff)
perf opt in set_data_packet
Diffstat (limited to 'src/packet_storage.c')
-rw-r--r--src/packet_storage.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/src/packet_storage.c b/src/packet_storage.c
index 39cff5c..bb8cdcd 100644
--- a/src/packet_storage.c
+++ b/src/packet_storage.c
@@ -343,30 +343,18 @@ uint64_t set_data_packet(struct data_packet *new_packet) {
struct data_packet_entry *current_entry = &packet_index[ cur_index ];
while (true) {
- if (current_entry->is_full) {
- static __thread byte decompressed[ sizeof(struct data_packet) ];
- uLongf decompressed_len = sizeof(struct data_packet);
- if (uncompress(
- decompressed,
- &decompressed_len,
- current_entry->compressed_payload,
- current_entry->compressed_size)
- == Z_OK) {
- if (memcmp(
- ((struct data_packet *) decompressed)->hash, new_packet->hash, sizeof(hash))
- == 0) {
- arena_free(current_entry->compressed_payload);
- current_entry->compressed_payload = compressed_payload;
- current_entry->compressed_size = compressed_len;
- pthread_mutex_unlock(&packet_storage_mutex);
- save_author_packet_hash(new_packet->contents.author, new_packet->hash);
- for (uint8_t i = 0; i < new_packet->contents.recipient_count; i++) {
- save_recipient_packet_hash(
- new_packet->contents.recipients[ i ], new_packet->hash);
- }
- return cur_index;
- }
+ if (current_entry->is_full &&
+ current_entry->compressed_size == compressed_len &&
+ memcmp(current_entry->compressed_payload, compressed_payload, compressed_len) == 0) {
+ arena_free(current_entry->compressed_payload);
+ current_entry->compressed_payload = compressed_payload;
+ current_entry->compressed_size = compressed_len;
+ pthread_mutex_unlock(&packet_storage_mutex);
+ save_author_packet_hash(new_packet->contents.author, new_packet->hash);
+ for (uint8_t i = 0; i < new_packet->contents.recipient_count; i++) {
+ save_recipient_packet_hash(new_packet->contents.recipients[ i ], new_packet->hash);
}
+ return cur_index;
}
if (current_entry->next == invalid_index) break;