From b9599a7119ae746de14f13c960d525d06d024095 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 2 Nov 2012 14:12:58 +0900 Subject: [PATCH] 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). --- tools/qfcc/include/set.h | 3 ++- tools/qfcc/source/set.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/qfcc/include/set.h b/tools/qfcc/include/set.h index f9f0c87bb..415075c54 100644 --- a/tools/qfcc/include/set.h +++ b/tools/qfcc/include/set.h @@ -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; diff --git a/tools/qfcc/source/set.c b/tools/qfcc/source/set.c index 23cd24e18..b0f855464 100644 --- a/tools/qfcc/source/set.c +++ b/tools/qfcc/source/set.c @@ -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