Patch #9307: Replace mem_malloc+memset with mem_calloc

Aside from reducing source code, on systems which use MEM_LIBC_MALLOC,
this has the potential to improve performance depending on the underlying
memory allocator

See http://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc
This commit is contained in:
Joel Cunningham
2017-04-05 13:38:20 -05:00
parent b34f2d5605
commit 557a11047d
6 changed files with 9 additions and 24 deletions

View File

@@ -1912,12 +1912,11 @@ mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl)
LWIP_ERROR("mdns_resp_add_netif: Hostname too long", (strlen(hostname) <= MDNS_LABEL_MAXLEN), return ERR_VAL);
LWIP_ASSERT("mdns_resp_add_netif: Double add", NETIF_TO_HOST(netif) == NULL);
mdns = (struct mdns_host *) mem_malloc(sizeof(struct mdns_host));
mdns = (struct mdns_host *) mem_calloc(1, sizeof(struct mdns_host));
LWIP_ERROR("mdns_resp_add_netif: Alloc failed", (mdns != NULL), return ERR_MEM);
netif_set_client_data(netif, mdns_netif_client_id, mdns);
memset(mdns, 0, sizeof(struct mdns_host));
MEMCPY(&mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname)));
mdns->dns_ttl = dns_ttl;
@@ -2020,11 +2019,9 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service
}
LWIP_ERROR("mdns_resp_add_service: Service list full (increase MDNS_MAX_SERVICES)", (slot >= 0), return ERR_MEM);
srv = (struct mdns_service*)mem_malloc(sizeof(struct mdns_service));
srv = (struct mdns_service*)mem_calloc(1, sizeof(struct mdns_service));
LWIP_ERROR("mdns_resp_add_service: Alloc failed", (srv != NULL), return ERR_MEM);
memset(srv, 0, sizeof(struct mdns_service));
MEMCPY(&srv->name, name, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(name)));
MEMCPY(&srv->service, service, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(service)));
srv->txt_fn = txt_fn;