aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-05-10 11:40:57 -0700
committerChris Robinson <[email protected]>2010-05-10 11:40:57 -0700
commit1652dc02abe309b7f7eafca7d9a4f4f81744bc55 (patch)
tree1444b19ba59501c7661b9fbf7bd535ca59bd0116 /Alc
parent099c2f3593074c42b736eeb325f8fb259b352dcf (diff)
Look for the map insertion point using a binary search
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 85d39872..56a08e9e 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -654,12 +654,23 @@ void ResetUIntMap(UIntMap *map)
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
{
- ALsizei pos;
+ ALsizei pos = 0;
- for(pos = 0;pos < map->size;pos++)
+ if(map->size > 0)
{
- if(map->array[pos].key >= key)
- break;
+ 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)
+ low++;
+ pos = low;
}
if(pos == map->size || map->array[pos].key != key)