]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Improve performance by using malloc() over calloc() in critical places
authorThomas Graf <tgr@lsx.localdomain>
Wed, 7 May 2008 11:18:30 +0000 (13:18 +0200)
committerThomas Graf <tgr@lsx.localdomain>
Wed, 7 May 2008 11:18:30 +0000 (13:18 +0200)
As pointed out by Regis Hanna, a considerable performance gain can be
achieved by using malloc() over calloc() when allocating netlink message
buffers. This is likely due to the fact that we use a complete page for
each message.

lib/msg.c
lib/nl.c

index 3d4fbc63a1f78214aea4f72ed6bf679e98487da6..c5cb7b42687da4050e04da413560f28a212456b1 100644 (file)
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -372,10 +372,12 @@ static struct nl_msg *__nlmsg_alloc(size_t len)
        if (!nm)
                goto errout;
 
-       nm->nm_nlh = calloc(1, len);
+       nm->nm_nlh = malloc(len);
        if (!nm->nm_nlh)
                goto errout;
 
+       memset(nm->nm_nlh, 0, sizeof(struct nlmsghdr));
+
        nm->nm_protocol = -1;
        nm->nm_size = len;
        nm->nm_nlh->nlmsg_len = nlmsg_total_size(0);
index 3281739ba605509440af6874b79ad4f0e4c07654..9b6fb9b65a76e3e5de1789a706083f409fbc29ef 100644 (file)
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -482,7 +482,7 @@ int nl_recv(struct nl_handle *handle, struct sockaddr_nl *nla,
                page_size = getpagesize();
 
        iov.iov_len = page_size;
-       iov.iov_base = *buf = calloc(1, iov.iov_len);
+       iov.iov_base = *buf = malloc(iov.iov_len);
 
        if (handle->h_flags & NL_SOCK_PASSCRED) {
                msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));