Compare commits
5 Commits
master
...
exponentia
Author | SHA1 | Date |
---|---|---|
Vftdan | c3af4ce4be | |
Vftdan | c5035fba81 | |
Vftdan | c118454ea5 | |
Vftdan | 4fc7f1d043 | |
Vftdan | 1e8bad5dd2 |
12
src/sfxd.c
12
src/sfxd.c
|
@ -16,6 +16,9 @@
|
|||
#define MAX_SOUNDS_PER_KEY 32
|
||||
#define MAX_SOURCE_DEPTH 32
|
||||
|
||||
// Set initial offset to size to distinguish start and end
|
||||
#define FOR_OFFSET_PROBE(base, offset, index, size) for (int offset = 0, index = (base) % (size); offset >= 0; offset = ((offset + 1) << 1L) % (((size) + 1) | 1) - 1, offset = offset == (size) ? (size) - 1 /* n * 2 = n - 1 (mod n + 1) */ : offset, index = ((base) + offset) % (size), offset = offset == 0 ? -1 : offset)
|
||||
|
||||
struct msg_target {
|
||||
FILE *file_handle;
|
||||
int sock_fd;
|
||||
|
@ -361,8 +364,7 @@ void sfx_pool_grow(int size) {
|
|||
for (int i = 0; i < sounds_pool.cap; i++) {
|
||||
if (sounds_pool.sounds[i].key[0] == '\0') continue;
|
||||
uint32_t new_hash = adler32(sounds_pool.sounds[i].key, strlen(sounds_pool.sounds[i].key));
|
||||
for (int offset = 0; offset < size; offset++) {
|
||||
int index = (new_hash + offset) % size;
|
||||
FOR_OFFSET_PROBE (new_hash, offset, index, size) {
|
||||
#ifndef NO_COUNTERS
|
||||
global_counters.pool_write++;
|
||||
if (offset != 0) {
|
||||
|
@ -386,8 +388,7 @@ void sfx_pool_grow(int size) {
|
|||
struct sfx_pool_item *sfx_pool_lookup(const char *key) {
|
||||
if (key == NULL) return NULL;
|
||||
uint32_t hash = adler32(key, strlen(key));
|
||||
for (int offset = 0; offset < sounds_pool.cap; offset++) {
|
||||
int index = (hash + offset) % sounds_pool.cap;
|
||||
FOR_OFFSET_PROBE (hash, offset, index, sounds_pool.cap) {
|
||||
if (0 == strncmp(key, sounds_pool.sounds[index].key, KEY_LENGTH)) {
|
||||
#ifndef NO_COUNTERS
|
||||
global_counters.pool_read++;
|
||||
|
@ -403,8 +404,7 @@ struct sfx_pool_item *sfx_pool_lookup(const char *key) {
|
|||
|
||||
struct sfx_pool_item *sfx_pool_find_place_for(const char *key) {
|
||||
uint32_t hash = adler32(key, strlen(key));
|
||||
for (int offset = 0; offset < sounds_pool.cap; offset++) {
|
||||
int index = (hash + offset) % sounds_pool.cap;
|
||||
FOR_OFFSET_PROBE (hash, offset, index, sounds_pool.cap) {
|
||||
if (sounds_pool.sounds[index].key[0] == '\0' || 0 == strncmp(sounds_pool.sounds[index].key, key, KEY_LENGTH)) {
|
||||
#ifndef NO_COUNTERS
|
||||
global_counters.pool_write++;
|
||||
|
|
Loading…
Reference in New Issue