diff --git a/libsepol/src/ebitmap.c b/libsepol/src/ebitmap.c index d23444ce..a5108b71 100644 --- a/libsepol/src/ebitmap.c +++ b/libsepol/src/ebitmap.c @@ -128,14 +128,15 @@ int ebitmap_andnot(ebitmap_t *dst, ebitmap_t *e1, ebitmap_t *e2, unsigned int ma unsigned int ebitmap_cardinality(ebitmap_t *e1) { - unsigned int i, count = 0; + unsigned int count = 0; + ebitmap_node_t *n; if (e1->cardinality || e1->highbit == 0) return e1->cardinality; - for (i=ebitmap_startbit(e1); i < ebitmap_length(e1); i++) - if (ebitmap_get_bit(e1, i)) - count++; + for (n = e1->node; n; n = n->next) { + count += __builtin_popcountll(n->map); + } e1->cardinality = count; return count; }