style: modernize lib/bitset.c

This commit is contained in:
Akim Demaille
2018-10-10 22:43:33 +02:00
parent 059cb26ca2
commit 72e2a94d5f

View File

@@ -39,11 +39,10 @@ const char * const bitset_type_names[] = BITSET_TYPE_NAMES;
size_t size_t
bitset_bytes (enum bitset_type type, bitset_bindex n_bits) bitset_bytes (enum bitset_type type, bitset_bindex n_bits)
{ {
size_t bytes;
if (bitset_stats_enabled) if (bitset_stats_enabled)
return bitset_stats_bytes (); return bitset_stats_bytes ();
size_t bytes;
switch (type) switch (type)
{ {
default: default:
@@ -134,12 +133,9 @@ bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned attr)
bitset bitset
bitset_alloc (bitset_bindex n_bits, enum bitset_type type) bitset_alloc (bitset_bindex n_bits, enum bitset_type type)
{ {
size_t bytes; size_t bytes = bitset_bytes (type, n_bits);
bitset bset;
bytes = bitset_bytes (type, n_bits); bitset bset = xcalloc (1, bytes);
bset = xcalloc (1, bytes);
/* The cache is disabled until some elements are allocated. If we /* The cache is disabled until some elements are allocated. If we
have variable length arrays, then we may need to allocate a dummy have variable length arrays, then we may need to allocate a dummy
@@ -154,12 +150,9 @@ bitset
bitset_obstack_alloc (struct obstack *bobstack, bitset_obstack_alloc (struct obstack *bobstack,
bitset_bindex n_bits, enum bitset_type type) bitset_bindex n_bits, enum bitset_type type)
{ {
size_t bytes; size_t bytes = bitset_bytes (type, n_bits);
bitset bset;
bytes = bitset_bytes (type, n_bits); bitset bset = obstack_alloc (bobstack, bytes);
bset = obstack_alloc (bobstack, bytes);
memset (bset, 0, bytes); memset (bset, 0, bytes);
return bitset_init (bset, n_bits, type); return bitset_init (bset, n_bits, type);
@@ -171,9 +164,7 @@ bitset_obstack_alloc (struct obstack *bobstack,
bitset bitset
bitset_create (bitset_bindex n_bits, unsigned attr) bitset_create (bitset_bindex n_bits, unsigned attr)
{ {
enum bitset_type type; enum bitset_type type = bitset_type_choose (n_bits, attr);
type = bitset_type_choose (n_bits, attr);
return bitset_alloc (n_bits, type); return bitset_alloc (n_bits, type);
} }
@@ -200,9 +191,7 @@ bitset_obstack_free (bitset bset)
enum bitset_type enum bitset_type
bitset_type_get (bitset bset) bitset_type_get (bitset bset)
{ {
enum bitset_type type; enum bitset_type type = BITSET_TYPE_ (bset);
type = BITSET_TYPE_ (bset);
if (type != BITSET_STATS) if (type != BITSET_STATS)
return type; return type;
@@ -214,9 +203,7 @@ bitset_type_get (bitset bset)
const char * const char *
bitset_type_name_get (bitset bset) bitset_type_name_get (bitset bset)
{ {
enum bitset_type type; enum bitset_type type = bitset_type_get (bset);
type = bitset_type_get (bset);
return bitset_type_names[type]; return bitset_type_names[type];
} }
@@ -240,7 +227,7 @@ bitset_next (bitset src, bitset_bindex bitno)
extern bool extern bool
bitset_compatible_p (bitset bset1, bitset bset2) bitset_compatible_p (bitset bset1, bitset bset2)
{ {
return BITSET_COMPATIBLE_ (bset1, bset2); return BITSET_COMPATIBLE_ (bset1, bset2);
} }
@@ -291,15 +278,13 @@ bitset_only_set_p (bitset src, bitset_bindex bitno)
static void static void
bitset_print (FILE *file, bitset bset, bool verbose) bitset_print (FILE *file, bitset bset, bool verbose)
{ {
unsigned pos;
bitset_bindex i;
bitset_iterator iter;
if (verbose) if (verbose)
fprintf (file, "n_bits = %lu, set = {", fprintf (file, "n_bits = %lu, set = {",
(unsigned long) bitset_size (bset)); (unsigned long) bitset_size (bset));
pos = 30; unsigned pos = 30;
bitset_bindex i;
bitset_iterator iter;
BITSET_FOR_EACH (iter, bset, i, 0) BITSET_FOR_EACH (iter, bset, i, 0)
{ {
if (pos > 70) if (pos > 70)
@@ -357,7 +342,7 @@ bitset_toggle_ (bitset bset, bitset_bindex bitno)
bitset_bindex bitset_bindex
bitset_size_ (bitset src) bitset_size_ (bitset src)
{ {
return BITSET_NBITS_ (src); return BITSET_NBITS_ (src);
} }
@@ -366,7 +351,6 @@ bitset_bindex
bitset_count_ (bitset src) bitset_count_ (bitset src)
{ {
bitset_bindex list[BITSET_LIST_SIZE]; bitset_bindex list[BITSET_LIST_SIZE];
bitset_bindex next;
bitset_bindex num; bitset_bindex num;
bitset_bindex count; bitset_bindex count;
@@ -374,7 +358,7 @@ bitset_count_ (bitset src)
bitset implementation that uses a direct technique (based on bitset implementation that uses a direct technique (based on
masks) for counting the number of bits set in a word. */ masks) for counting the number of bits set in a word. */
next = 0; bitset_bindex next = 0;
for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next)); for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next));
count += num) count += num)
continue; continue;
@@ -411,13 +395,11 @@ bitset_op4_cmp (bitset dst, bitset src1, bitset src2, bitset src3,
enum bitset_ops op) enum bitset_ops op)
{ {
bool changed = false; bool changed = false;
bool stats_enabled_save;
bitset tmp;
/* Create temporary bitset. */ /* Create temporary bitset. */
stats_enabled_save = bitset_stats_enabled; bool stats_enabled_save = bitset_stats_enabled;
bitset_stats_enabled = false; bitset_stats_enabled = false;
tmp = bitset_alloc (0, bitset_type_get (dst)); bitset tmp = bitset_alloc (0, bitset_type_get (dst));
bitset_stats_enabled = stats_enabled_save; bitset_stats_enabled = stats_enabled_save;
switch (op) switch (op)