diff options
author | Chris Robinson <[email protected]> | 2016-07-04 09:18:49 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-07-04 10:26:46 -0700 |
commit | f0cbcdc928b6a0615199dde56f3b7f0ac31cc6cb (patch) | |
tree | b29066f3d18af4022a18a930accc82f1bd84b70b /common/uintmap.c | |
parent | 80da138d7f78ddb5a91b5644001d2aa1da4f7a61 (diff) |
Use al_malloc/al_free for the UIntMap array
Diffstat (limited to 'common/uintmap.c')
-rw-r--r-- | common/uintmap.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/common/uintmap.c b/common/uintmap.c index d5e7c9ae..041f46c1 100644 --- a/common/uintmap.c +++ b/common/uintmap.c @@ -6,6 +6,8 @@ #include <stdlib.h> #include <string.h> +#include "almalloc.h" + extern inline void LockUIntMapRead(UIntMap *map); extern inline void UnlockUIntMapRead(UIntMap *map); @@ -17,7 +19,7 @@ void InitUIntMap(UIntMap *map, ALsizei limit) { map->array = NULL; map->size = 0; - map->maxsize = 0; + map->capacity = 0; map->limit = limit; RWLockInit(&map->lock); } @@ -25,10 +27,10 @@ void InitUIntMap(UIntMap *map, ALsizei limit) void ResetUIntMap(UIntMap *map) { WriteLock(&map->lock); - free(map->array); + al_free(map->array); map->array = NULL; map->size = 0; - map->maxsize = 0; + map->capacity = 0; WriteUnlock(&map->lock); } @@ -62,21 +64,27 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) return AL_OUT_OF_MEMORY; } - if(map->size == map->maxsize) + if(map->size == map->capacity) { ALvoid *temp = NULL; ALsizei newsize; - newsize = (map->maxsize ? (map->maxsize<<1) : 4); - if(newsize >= map->maxsize) - temp = realloc(map->array, newsize*sizeof(map->array[0])); + newsize = (map->capacity ? (map->capacity<<1) : 4); + if(map->limit > 0 && newsize > map->limit) + newsize = map->limit; + if(newsize > map->capacity) + temp = al_malloc(16, newsize * sizeof(map->array[0])); if(!temp) { WriteUnlock(&map->lock); return AL_OUT_OF_MEMORY; } + + if(map->array) + memcpy(temp, map->array, map->size*sizeof(map->array[0])); + al_free(map->array); map->array = temp; - map->maxsize = newsize; + map->capacity = newsize; } if(pos < map->size) |