hashtable: Don't rearrange bucket elements during SDL_FindInHashTable.
This is a race condition if the hashtable isn't protected by a mutex, and it makes a read/write operation out of something what appears to be read-only, which is dangerously surprising from an interface viewpoint. The downside is that if you have an item that is frequently accessed that isn't in the first slot of a bucket, each find operation will take longer instead of common items bubbling to the front of the bucket. Then again, if you have several common things being looked up in rotation, they'll just be doing unnecessary shuffling here. In this case, it might be better to just use a larger hashtable or a better hashing function (or just look up the thing you need once instead of multiple times). Fixes #8391.main
parent
8ac5c84ad1
commit
6664437748
|
@ -116,16 +116,6 @@ SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const
|
|||
if (_value != NULL) {
|
||||
*_value = i->value;
|
||||
}
|
||||
|
||||
/* Matched! Move to the front of list for faster lookup next time.
|
||||
(stackable tables have to remain in the same order, though!) */
|
||||
if ((!table->stackable) && (prev != NULL)) {
|
||||
SDL_assert(prev->next == i);
|
||||
prev->next = i->next;
|
||||
i->next = table->table[hash];
|
||||
table->table[hash] = i;
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue