Now that a pointer to all the bit storage doesn't escape vector.c,
there's no need to allocate storage, that's initialised to 0, just to
then clear a bit in it. Only extend the bits's storage for set bits.
Remove the unused initial size parameter from bvector_create() as it
simplifies the implementation.
*/
typedef struct bvector *bvector_t;
*/
typedef struct bvector *bvector_t;
-bvector_t bvector_create (size_t /* initial size in bits, can be 0 */);
+bvector_t bvector_create (void);
void bvector_copy (bvector_t, bvector_t);
void bvector_free (bvector_t);
void bvector_clear (bvector_t, size_t);
void bvector_copy (bvector_t, bvector_t);
void bvector_free (bvector_t);
void bvector_clear (bvector_t, size_t);
#define make_seq_private(mp,seqnum) \
bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
#define make_all_public(mp) \
#define make_seq_private(mp,seqnum) \
bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
#define make_all_public(mp) \
- mp->attrstats = bvector_create(0); bvector_clear_all (mp->attrstats)
+ mp->attrstats = bvector_create(); bvector_clear_all (mp->attrstats)
/*
* macros for folder attributes
/*
* macros for folder attributes
mp->num_msgstats = MSGSTATNUM (mp->lowoff, mp->hghoff);
mp->msgstats = mh_xmalloc (MSGSTATSIZE(mp));
for (i = 0, v = mp->msgstats; i < mp->num_msgstats; ++i, ++v) {
mp->num_msgstats = MSGSTATNUM (mp->lowoff, mp->hghoff);
mp->msgstats = mh_xmalloc (MSGSTATSIZE(mp));
for (i = 0, v = mp->msgstats; i < mp->num_msgstats; ++i, ++v) {
- *v = bvector_create (0);
+ *v = bvector_create ();
}
mp->msgattrs = svector_create (0);
}
mp->msgattrs = svector_create (0);
mh_xrealloc (mp->msgstats, MSGSTATSIZE(mp));
for (i = old_size, v = &mp->msgstats[old_size]; i < new_size;
++i, ++v) {
mh_xrealloc (mp->msgstats, MSGSTATSIZE(mp));
for (i = old_size, v = &mp->msgstats[old_size]; i < new_size;
++i, ++v) {
- *v = bvector_create (0);
+ *v = bvector_create ();
mp->num_msgstats = MSGSTATNUM (lo, hi);
tmpstats = mh_xmalloc (MSGSTATSIZE(mp));
for (i = 0, t = tmpstats; i < mp->num_msgstats; ++i, ++t) {
mp->num_msgstats = MSGSTATNUM (lo, hi);
tmpstats = mh_xmalloc (MSGSTATSIZE(mp));
for (i = 0, t = tmpstats; i < mp->num_msgstats; ++i, ++t) {
- *t = bvector_create (0);
+ *t = bvector_create ();
}
/* then copy messages status array with shift */
}
/* then copy messages status array with shift */
static void bvector_resize (bvector_t vec, size_t newsize);
bvector_t
static void bvector_resize (bvector_t vec, size_t newsize);
bvector_t
-bvector_create (size_t init_size) {
/* See "wider than unsigned long" comment above. */
assert (sizeof *vec->bits <= sizeof 1ul);
NEW(vec);
/* See "wider than unsigned long" comment above. */
assert (sizeof *vec->bits <= sizeof 1ul);
NEW(vec);
-
- if (init_size <= BVEC_INIT_SIZE) {
- vec->bits = vec->tiny;
- vec->maxsize = BVEC_INIT_SIZE;
- memset(vec->tiny, 0, sizeof vec->tiny);
- return vec;
- }
-
- bytes = BVEC_BYTES(init_size);
- vec->bits = mh_xcalloc (1, bytes);
- vec->maxsize = bytes * CHAR_BIT;
+ vec->bits = vec->tiny;
+ vec->maxsize = BVEC_INIT_SIZE;
+ memset(vec->tiny, 0, sizeof vec->tiny);
void
bvector_clear (bvector_t vec, size_t n) {
void
bvector_clear (bvector_t vec, size_t n) {
- size_t word = BVEC_WORD(n);
- size_t offset = BVEC_OFFSET(n);
-
- if (n >= vec->maxsize)
- bvector_resize (vec, n);
-
- vec->bits[word] &= ~(1ul << offset);
+ if (n < vec->maxsize)
+ vec->bits[BVEC_WORD(n)] &= ~(1ul << BVEC_OFFSET(n));
unsigned int
bvector_at (bvector_t vec, size_t i) {
unsigned int
bvector_at (bvector_t vec, size_t i) {
- size_t word = BVEC_WORD(i);
- size_t offset = BVEC_OFFSET(i);
+ if (i < vec->maxsize)
+ return !!(vec->bits[BVEC_WORD(i)] & (1ul << BVEC_OFFSET(i)));
- return i < vec->maxsize
- ? (vec->bits[word] & (1ul << offset) ? 1 : 0)
- : 0;
rename_msgs (struct msgs *mp, struct smsg **mlist)
{
int i, j, old, new;
rename_msgs (struct msgs *mp, struct smsg **mlist)
{
int i, j, old, new;
- bvector_t tmpset = bvector_create (0);
+ bvector_t tmpset = bvector_create ();
char f1[BUFSIZ], tmpfil[BUFSIZ];
char newbuf[PATH_MAX + 1];
struct smsg *sp;
char f1[BUFSIZ], tmpfil[BUFSIZ];
char newbuf[PATH_MAX + 1];
struct smsg *sp;