shared/bitmap: minor modernizations

This commit is contained in:
Mike Yuan
2025-05-26 20:24:47 +02:00
parent 5a881f7f71
commit fae687ec2b
2 changed files with 6 additions and 8 deletions
+3 -5
View File
@@ -123,13 +123,12 @@ bool bitmap_isset(const Bitmap *b, unsigned n) {
}
bool bitmap_isclear(const Bitmap *b) {
unsigned i;
if (!b)
return true;
for (i = 0; i < b->n_bitmaps; i++)
if (b->bitmaps[i] != 0)
FOREACH_ARRAY(i, b->bitmaps, b->n_bitmaps)
if (*i != 0)
return false;
return true;
@@ -181,7 +180,6 @@ bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n) {
bool bitmap_equal(const Bitmap *a, const Bitmap *b) {
size_t common_n_bitmaps;
const Bitmap *c;
unsigned i;
if (a == b)
return true;
@@ -197,7 +195,7 @@ bool bitmap_equal(const Bitmap *a, const Bitmap *b) {
return false;
c = a->n_bitmaps > b->n_bitmaps ? a : b;
for (i = common_n_bitmaps; i < c->n_bitmaps; i++)
for (unsigned i = common_n_bitmaps; i < c->n_bitmaps; i++)
if (c->bitmaps[i] != 0)
return false;
+3 -3
View File
@@ -16,13 +16,13 @@ Bitmap* bitmap_free(Bitmap *b);
int bitmap_set(Bitmap *b, unsigned n);
void bitmap_unset(Bitmap *b, unsigned n);
bool bitmap_isset(const Bitmap *b, unsigned n);
bool bitmap_isclear(const Bitmap *b);
bool bitmap_isset(const Bitmap *b, unsigned n) _pure_;
bool bitmap_isclear(const Bitmap *b) _pure_;
void bitmap_clear(Bitmap *b);
bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n);
bool bitmap_equal(const Bitmap *a, const Bitmap *b);
bool bitmap_equal(const Bitmap *a, const Bitmap *b) _pure_;
#define _BITMAP_FOREACH(n, b, i) \
for (Iterator i = {}; bitmap_iterate((b), &i, (unsigned*)&(n)); )