From 81133769def858c663718dc3e676d288594e0d66 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 6 Oct 2011 06:39:13 -0700 Subject: [PATCH] Return the key's value from the map when it's removed --- Alc/helpers.c | 34 ++++------------------------------ OpenAL32/Include/alMain.h | 13 ++++++------- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/Alc/helpers.c b/Alc/helpers.c index 980c0071..f219f4ae 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -391,8 +391,9 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) return AL_NO_ERROR; } -void RemoveUIntMapKey(UIntMap *map, ALuint key) +ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key) { + ALvoid *ptr = NULL; WriteLock(&map->lock); if(map->size > 0) { @@ -408,6 +409,7 @@ void RemoveUIntMapKey(UIntMap *map, ALuint key) } if(map->array[low].key == key) { + ptr = map->array[low].value; if(low < map->size-1) memmove(&map->array[low], &map->array[low+1], (map->size-1-low)*sizeof(map->array[0])); @@ -415,6 +417,7 @@ void RemoveUIntMapKey(UIntMap *map, ALuint key) } } WriteUnlock(&map->lock); + return ptr; } ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) @@ -439,32 +442,3 @@ ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) ReadUnlock(&map->lock); return ptr; } - -ALvoid *PopUIntMapValue(UIntMap *map, ALuint key) -{ - ALvoid *ptr = NULL; - WriteLock(&map->lock); - if(map->size > 0) - { - ALsizei low = 0; - ALsizei high = map->size - 1; - while(low < high) - { - ALsizei mid = low + (high-low)/2; - if(map->array[mid].key < key) - low = mid + 1; - else - high = mid; - } - if(map->array[low].key == key) - { - ptr = map->array[low].value; - if(low < map->size-1) - memmove(&map->array[low], &map->array[low+1], - (map->size-1-low)*sizeof(map->array[0])); - map->size--; - } - } - WriteUnlock(&map->lock); - return ptr; -} diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index a6ef8bb3..8a9e8d59 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -427,9 +427,8 @@ extern UIntMap TlsDestructor; void InitUIntMap(UIntMap *map, ALsizei limit); void ResetUIntMap(UIntMap *map); ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); -void RemoveUIntMapKey(UIntMap *map, ALuint key); +ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key); ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key); -ALvoid *PopUIntMapValue(UIntMap *map, ALuint key); static __inline void LockUIntMapRead(UIntMap *map) { ReadLock(&map->lock); } @@ -703,9 +702,9 @@ struct ALCdevice_struct #define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k))) #define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k))) #define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k))) -#define RemoveBuffer(m, k) ((struct ALbuffer*)PopUIntMapValue(&(m)->BufferMap, (k))) -#define RemoveEffect(m, k) ((struct ALeffect*)PopUIntMapValue(&(m)->EffectMap, (k))) -#define RemoveFilter(m, k) ((struct ALfilter*)PopUIntMapValue(&(m)->FilterMap, (k))) +#define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k))) +#define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k))) +#define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k))) struct ALCcontext_struct @@ -745,8 +744,8 @@ struct ALCcontext_struct #define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k))) #define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k))) -#define RemoveSource(m, k) ((struct ALsource*)PopUIntMapValue(&(m)->SourceMap, (k))) -#define RemoveEffectSlot(m, k) ((struct ALeffectslot*)PopUIntMapValue(&(m)->EffectSlotMap, (k))) +#define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k))) +#define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k))) ALCcontext *GetContextRef(void); -- 2.11.4.GIT