From 49539eb2533017a0865d804d9592db2df3f659f0 Mon Sep 17 00:00:00 2001 From: yangwei Date: Wed, 31 Jul 2024 00:00:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(pacekt=20and=20tcp=5Fsegmen?= =?UTF-8?q?t=20init):=20reduce=20memset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packet/packet_utils.cpp | 2 +- src/stellar/stellar_core.cpp | 2 +- src/tcp_reassembly/tcp_reassembly.cpp | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/packet/packet_utils.cpp b/src/packet/packet_utils.cpp index dd14c8e..9048242 100644 --- a/src/packet/packet_utils.cpp +++ b/src/packet/packet_utils.cpp @@ -490,7 +490,7 @@ uint16_t packet_get_payload_len(const struct packet *pkt) struct packet *packet_new(uint16_t pkt_len) { - struct packet *pkt = (struct packet *)calloc(1, sizeof(struct packet) + pkt_len); + struct packet *pkt = (struct packet *)malloc( sizeof(struct packet) + pkt_len); if (pkt == NULL) { return NULL; diff --git a/src/stellar/stellar_core.cpp b/src/stellar/stellar_core.cpp index 83ea43d..cf3639e 100644 --- a/src/stellar/stellar_core.cpp +++ b/src/stellar/stellar_core.cpp @@ -185,7 +185,7 @@ static void *work_thread(void *arg) * Suggestion: After modifying the system time, restart the service to ensure consistent timing. */ now_ms = stellar_get_real_time_msec(); - memset(packets, 0, sizeof(packets)); + //memset(packets, 0, sizeof(packets)); nr_recv = packet_io_ingress(packet_io, thr_idx, packets, RX_BURST_MAX); if (nr_recv == 0) { diff --git a/src/tcp_reassembly/tcp_reassembly.cpp b/src/tcp_reassembly/tcp_reassembly.cpp index 09de07c..61a5b14 100644 --- a/src/tcp_reassembly/tcp_reassembly.cpp +++ b/src/tcp_reassembly/tcp_reassembly.cpp @@ -32,13 +32,7 @@ struct tcp_reassembly struct tcp_segment *tcp_segment_new(uint32_t seq, const void *data, uint32_t len) { - struct tcp_segment_private *p = (struct tcp_segment_private *)calloc(1, sizeof(struct tcp_segment_private) + len); - if (!p) - { - TCP_REASSEMBLY_LOG_ERROR("calloc failed"); - return NULL; - } - + struct tcp_segment_private *p = (struct tcp_segment_private *)malloc(sizeof(struct tcp_segment_private) + len); p->node.start = seq; p->node.last = (uint64_t)seq + (uint64_t)len - 1; p->data = (char *)p + sizeof(struct tcp_segment_private);