diff mbox series

[7/7] libsepol: skip superfluous memset calls in ebitmap operations

Message ID 20220712160858.22677-7-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit fc7bb9f05a3e
Headers show
Series [1/7] libsepol/tests: add ebitmap tests | expand

Commit Message

Christian Göttsche July 12, 2022, 4:08 p.m. UTC
The three members of struct ebitmap_node are all unconditionally
initialized.  Hinder compilers to optimize malloc() and memset() into
calloc(), which might be slightly slower.  Especially affects
ebitmap_or().

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsepol/src/ebitmap.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

James Carter July 18, 2022, 8:48 p.m. UTC | #1
On Tue, Jul 12, 2022 at 12:09 PM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> The three members of struct ebitmap_node are all unconditionally
> initialized.  Hinder compilers to optimize malloc() and memset() into
> calloc(), which might be slightly slower.  Especially affects
> ebitmap_or().
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libsepol/src/ebitmap.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c
> index e0541abb..d0f7daba 100644
> --- a/libsepol/src/ebitmap.c
> +++ b/libsepol/src/ebitmap.c
> @@ -31,7 +31,6 @@ int ebitmap_or(ebitmap_t * dst, const ebitmap_t * e1, const ebitmap_t * e2)
>                         ebitmap_destroy(dst);
>                         return -ENOMEM;
>                 }
> -               memset(new, 0, sizeof(ebitmap_node_t));
>                 if (n1 && n2 && n1->startbit == n2->startbit) {
>                         new->startbit = n1->startbit;
>                         new->map = n1->map | n2->map;
> @@ -289,7 +288,6 @@ int ebitmap_cpy(ebitmap_t * dst, const ebitmap_t * src)
>                         ebitmap_destroy(dst);
>                         return -ENOMEM;
>                 }
> -               memset(new, 0, sizeof(ebitmap_node_t));
>                 new->startbit = n->startbit;
>                 new->map = n->map;
>                 new->next = 0;
> @@ -429,7 +427,6 @@ int ebitmap_set_bit(ebitmap_t * e, unsigned int bit, int value)
>         new = (ebitmap_node_t *) malloc(sizeof(ebitmap_node_t));
>         if (!new)
>                 return -ENOMEM;
> -       memset(new, 0, sizeof(ebitmap_node_t));
>
>         new->startbit = startbit;
>         new->map = (MAPBIT << (bit - new->startbit));
> --
> 2.36.1
>
diff mbox series

Patch

diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c
index e0541abb..d0f7daba 100644
--- a/libsepol/src/ebitmap.c
+++ b/libsepol/src/ebitmap.c
@@ -31,7 +31,6 @@  int ebitmap_or(ebitmap_t * dst, const ebitmap_t * e1, const ebitmap_t * e2)
 			ebitmap_destroy(dst);
 			return -ENOMEM;
 		}
-		memset(new, 0, sizeof(ebitmap_node_t));
 		if (n1 && n2 && n1->startbit == n2->startbit) {
 			new->startbit = n1->startbit;
 			new->map = n1->map | n2->map;
@@ -289,7 +288,6 @@  int ebitmap_cpy(ebitmap_t * dst, const ebitmap_t * src)
 			ebitmap_destroy(dst);
 			return -ENOMEM;
 		}
-		memset(new, 0, sizeof(ebitmap_node_t));
 		new->startbit = n->startbit;
 		new->map = n->map;
 		new->next = 0;
@@ -429,7 +427,6 @@  int ebitmap_set_bit(ebitmap_t * e, unsigned int bit, int value)
 	new = (ebitmap_node_t *) malloc(sizeof(ebitmap_node_t));
 	if (!new)
 		return -ENOMEM;
-	memset(new, 0, sizeof(ebitmap_node_t));
 
 	new->startbit = startbit;
 	new->map = (MAPBIT << (bit - new->startbit));