加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
performance-change-memset-location.patch 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
alexchen 提交于 2021-03-15 20:03 . performance: change memset location
From 23915d6eff1ba63c5a9967a519879225312ead01 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Mon, 15 Mar 2021 20:03:18 +0800
Subject: [PATCH] performance: change memset location
There is no need to clear all mem in add_domains, beacause memcpy will
write the front section. We only need to clear the mem in the end, which
will improve the performance.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/domain.c b/src/domain.c
index b8c527a..977cabe 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -55,11 +55,12 @@ struct domain *add_domains(struct domain_list *list)
if (new_list == NULL) {
return NULL;
}
- memset(new_list, 0, sizeof(struct domain) * (list->num + 1));
memcpy(new_list, list->domains, sizeof(struct domain) * list->num);
free(list->domains);
list->domains = new_list;
list->num++;
+ memset(&(list->domains[list->num - 1]), 0, sizeof(struct domain));
+
return &(list->domains[list->num - 1]);
}
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化