From c53365efc1f4796e431df35a51abdadb64d080f6 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 May 2025 02:11:14 +0200 Subject: [PATCH] tiny optimization for hashtables --- src/hashtable.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hashtable.c b/src/hashtable.c index cd56a8a34..ddee6c3e9 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -47,7 +47,9 @@ void mobjnum_ht_linkedList_AddEntry(thinker_t* thinker) mobjnum_linkedList* currentEntry; // = &mobjnum_Hashtable[(UINT8)(mobj->mobjnum % HT_NUMLISTS)]; mobjnum_linkedList* next; - currentEntry = &mobjnum_Hashtable[(UINT8)(((mobj_t*)thinker)->mobjnum % HT_NUMLISTS)]; + const UINT8 listidx = (UINT8)(((mobj_t*)thinker)->mobjnum % HT_NUMLISTS); + + currentEntry = &mobjnum_Hashtable[listidx]; if (!currentEntry->next) // check for the first entry { @@ -60,7 +62,7 @@ void mobjnum_ht_linkedList_AddEntry(thinker_t* thinker) return; } - for (currentEntry = &mobjnum_Hashtable[(UINT8)(((mobj_t*)thinker)->mobjnum % HT_NUMLISTS)]; currentEntry != NULL; currentEntry = next) + for (currentEntry = &mobjnum_Hashtable[listidx]; currentEntry != NULL; currentEntry = next) { if (!currentEntry->thinker) { @@ -106,15 +108,15 @@ void mobjnum_ht_linkedList_AddEntry(thinker_t* thinker) */ thinker_t* mobjnum_ht_linkedList_Find(UINT32 mobjnumber) { - // mobjnum_linkedList* currentEntry = &mobjnum_Hashtable[(UINT8)(mobjnumber % HT_NUMLISTS)]; - mobjnum_linkedList* currentEntry; // = &mobjnum_Hashtable[(UINT8)(mobj->mobjnum % HT_NUMLISTS)]; mobjnum_linkedList* next; if (!mobjnumber) return NULL; - currentEntry = &mobjnum_Hashtable[(UINT8)(mobjnumber % HT_NUMLISTS)]; + const UINT8 listidx = (UINT8)(mobjnumber % HT_NUMLISTS); + + currentEntry = &mobjnum_Hashtable[listidx]; if (!currentEntry->next) // check for the first entry { @@ -125,7 +127,7 @@ thinker_t* mobjnum_ht_linkedList_Find(UINT32 mobjnumber) return currentEntry->thinker; } - for (currentEntry = &mobjnum_Hashtable[(UINT8)(mobjnumber % HT_NUMLISTS)]; currentEntry != NULL; currentEntry = next) + for (currentEntry = &mobjnum_Hashtable[listidx]; currentEntry != NULL; currentEntry = next) { if (!currentEntry->thinker) return NULL;