Better set memory management.

At the cost of one pointer per set, sets can now be allocated and freed
more efficiently (especially since malloc might round things up).
This commit is contained in:
Bill Currie 2012-11-02 14:12:58 +09:00
parent 2385cf65c2
commit b9599a7119
2 changed files with 6 additions and 3 deletions

View file

@ -37,8 +37,9 @@
//@{
typedef struct set_s {
unsigned size;
struct set_s *next; //< private. for ALLOC
unsigned *map;
unsigned size;
unsigned defmap[8];
} set_t;

View file

@ -48,6 +48,7 @@
#define BITS (sizeof (unsigned) * 8)
set_t *free_sets;
set_iter_t *free_set_iters;
static set_iter_t *
@ -76,7 +77,7 @@ set_new (void)
{
set_t *set;
set = calloc (1, sizeof (set_t));
ALLOC (16, set_t, sets, set);
set->size = sizeof (set->defmap) * 8;
set->map = set->defmap;
return set;
@ -87,7 +88,8 @@ set_delete (set_t *set)
{
if (set->map != set->defmap)
free (set->map);
free (set);
set->next = free_sets;
free_sets = set;
}
static void