83 lines
2.0 KiB
Diff
83 lines
2.0 KiB
Diff
|
From 12a8a00bf21df7aad13348b7300f7e4474d10809 Mon Sep 17 00:00:00 2001
|
||
|
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
|
||
|
Date: Tue, 19 Jul 2022 17:30:41 +0200
|
||
|
Subject: [PATCH] libsepol: optimize ebitmap_not
|
||
|
MIME-Version: 1.0
|
||
|
Content-Type: text/plain; charset=UTF-8
|
||
|
Content-Transfer-Encoding: 8bit
|
||
|
Content-type: text/plain
|
||
|
|
||
|
Iterate on nodes instead of single bits to save node resolution for each
|
||
|
single bit.
|
||
|
|
||
|
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
|
||
|
Acked-by: James Carter <jwcart2@gmail.com>
|
||
|
---
|
||
|
libsepol/src/ebitmap.c | 48 ++++++++++++++++++++++++++++++++++++------
|
||
|
1 file changed, 42 insertions(+), 6 deletions(-)
|
||
|
|
||
|
diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c
|
||
|
index 0f9afd621fed..c9164c5e77bb 100644
|
||
|
--- a/libsepol/src/ebitmap.c
|
||
|
+++ b/libsepol/src/ebitmap.c
|
||
|
@@ -101,14 +101,50 @@ int ebitmap_xor(ebitmap_t *dst, const ebitmap_t *e1, const ebitmap_t *e2)
|
||
|
|
||
|
int ebitmap_not(ebitmap_t *dst, const ebitmap_t *e1, unsigned int maxbit)
|
||
|
{
|
||
|
- unsigned int i;
|
||
|
+ const ebitmap_node_t *n;
|
||
|
+ ebitmap_node_t *new, *prev = NULL;
|
||
|
+ uint32_t startbit, cur_startbit;
|
||
|
+ MAPTYPE map;
|
||
|
+
|
||
|
ebitmap_init(dst);
|
||
|
- for (i=0; i < maxbit; i++) {
|
||
|
- int val = ebitmap_get_bit(e1, i);
|
||
|
- int rc = ebitmap_set_bit(dst, i, !val);
|
||
|
- if (rc < 0)
|
||
|
- return rc;
|
||
|
+
|
||
|
+ n = e1->node;
|
||
|
+ for (cur_startbit = 0; cur_startbit < maxbit; cur_startbit += MAPSIZE) {
|
||
|
+ if (n && n->startbit == cur_startbit) {
|
||
|
+ startbit = n->startbit;
|
||
|
+ map = ~n->map;
|
||
|
+
|
||
|
+ n = n->next;
|
||
|
+ } else {
|
||
|
+ startbit = cur_startbit;
|
||
|
+ map = ~((MAPTYPE) 0);
|
||
|
+ }
|
||
|
+
|
||
|
+ if (maxbit - cur_startbit < MAPSIZE)
|
||
|
+ map &= (((MAPTYPE)1) << (maxbit - cur_startbit)) - 1;
|
||
|
+
|
||
|
+ if (map != 0) {
|
||
|
+ new = malloc(sizeof(ebitmap_node_t));
|
||
|
+ if (!new) {
|
||
|
+ ebitmap_destroy(dst);
|
||
|
+ return -ENOMEM;
|
||
|
+ }
|
||
|
+
|
||
|
+ new->startbit = startbit;
|
||
|
+ new->map = map;
|
||
|
+ new->next = NULL;
|
||
|
+
|
||
|
+ if (prev)
|
||
|
+ prev->next = new;
|
||
|
+ else
|
||
|
+ dst->node = new;
|
||
|
+ prev = new;
|
||
|
+ }
|
||
|
}
|
||
|
+
|
||
|
+ if (prev)
|
||
|
+ dst->highbit = prev->startbit + MAPSIZE;
|
||
|
+
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
--
|
||
|
2.38.1
|
||
|
|