From: Akim Demaille Date: Tue, 19 Mar 2019 20:26:35 +0000 (+0100) Subject: bitset: minor changes X-Git-Tag: v1.0~5008 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0f3c79720da3ef9478df1b06e2828af0e210b7de;p=gnulib.git bitset: minor changes * lib/bitset/base.h (bitset_alloc_type): Remove, unused. * lib/bitset/table.c: Formatting changes. Remove useless braces. Prefer using else in cascades of if/else-if with returns. * lib/bitset/vector.c: Reduce scopes. --- diff --git a/ChangeLog b/ChangeLog index 714610027a..88a3a40e11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2019-03-19 Akim Demaille + + bitset: minor changes + * lib/bitset/base.h (bitset_alloc_type): Remove, unused. + * lib/bitset/table.c: Formatting changes. + Remove useless braces. + Prefer using else in cascades of if/else-if with returns. + * lib/bitset/vector.c: Reduce scopes. + 2019-03-19 Akim Demaille bitset: expose bitset_resize diff --git a/lib/bitset/base.h b/lib/bitset/base.h index 4fcafac8b6..fe1b8fbe12 100644 --- a/lib/bitset/base.h +++ b/lib/bitset/base.h @@ -55,8 +55,6 @@ enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VECTOR, extern const char * const bitset_type_names[]; -enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC}; - /* Data type used to store a word of bits. */ typedef unsigned long bitset_word; #define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word))) diff --git a/lib/bitset/table.c b/lib/bitset/table.c index 9cac964694..07184d6574 100644 --- a/lib/bitset/table.c +++ b/lib/bitset/table.c @@ -188,21 +188,21 @@ tbitset_elt_alloc (void) /* Let particular systems override the size of a chunk. */ #ifndef OBSTACK_CHUNK_SIZE -#define OBSTACK_CHUNK_SIZE 0 +# define OBSTACK_CHUNK_SIZE 0 #endif /* Let them override the alloc and free routines too. */ #ifndef OBSTACK_CHUNK_ALLOC -#define OBSTACK_CHUNK_ALLOC xmalloc +# define OBSTACK_CHUNK_ALLOC xmalloc #endif #ifndef OBSTACK_CHUNK_FREE -#define OBSTACK_CHUNK_FREE free +# define OBSTACK_CHUNK_FREE free #endif #if ! defined __GNUC__ || __GNUC__ < 2 -#define __alignof__(type) 0 +# define __alignof__(type) 0 #endif obstack_specify_allocation (&tbitset_obstack, OBSTACK_CHUNK_SIZE, @@ -1018,13 +1018,9 @@ tbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) } if (!tbitset_elt_zero_p (delt)) - { - tbitset_elt_add (dst, delt, j); - } + tbitset_elt_add (dst, delt, j); else - { - tbitset_elt_free (delt); - } + tbitset_elt_free (delt); } /* If we have elements of DST left over, free them all. */ @@ -1059,7 +1055,8 @@ tbitset_and_cmp (bitset dst, bitset src1, bitset src2) tbitset_zero (dst); return changed; } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); } @@ -1074,9 +1071,7 @@ static bool tbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) { tbitset_weed (dst); @@ -1084,7 +1079,8 @@ tbitset_andn_cmp (bitset dst, bitset src1, bitset src2) tbitset_zero (dst); return changed; } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); } @@ -1099,14 +1095,11 @@ static bool tbitset_or_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) - { - return tbitset_copy_cmp (dst, src2); - } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); + return tbitset_copy_cmp (dst, src2); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); } @@ -1121,14 +1114,11 @@ static bool tbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) - { - return tbitset_copy_cmp (dst, src2); - } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); + return tbitset_copy_cmp (dst, src2); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); } diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c index 15d3e99567..0623651dc4 100644 --- a/lib/bitset/vector.c +++ b/lib/bitset/vector.c @@ -467,7 +467,6 @@ vbitset_and (bitset dst, bitset src1, bitset src2) static bool vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -477,6 +476,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -546,7 +546,6 @@ vbitset_andn (bitset dst, bitset src1, bitset src2) static bool vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -556,6 +555,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -633,8 +633,6 @@ vbitset_or (bitset dst, bitset src1, bitset src2) static bool vbitset_or_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -644,6 +642,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -711,7 +710,6 @@ vbitset_xor (bitset dst, bitset src1, bitset src2) static bool vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -721,6 +719,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -903,8 +902,8 @@ vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex size = VBITSET_SIZE (dst); - unsigned i; bool changed = false; + unsigned i; for (i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;