diff --git a/src/common/hashtab.c b/src/common/hashtab.c index 7c7f0e229..4bfa05689 100644 --- a/src/common/hashtab.c +++ b/src/common/hashtab.c @@ -77,7 +77,22 @@ static void HT_Alloc (HashTable* T) HashNode* HT_Find (const HashTable* T, const void* Key) /* Find the node with the given index */ { - unsigned Hash; + /* If we don't have a table, there's nothing to find */ + if (T->Table == 0) { + return 0; + } + + /* Search for the entry */ + return HT_FindHash (T, Key, T->Func->GenHash (Key)); +} + + + +HashNode* HT_FindHash (const HashTable* T, const void* Key, unsigned Hash) +/* Find the node with the given key. Differs from HT_Find in that the hash + * for the key is precalculated and passed to the function. + */ +{ HashNode* N; /* If we don't have a table, there's nothing to find */ @@ -85,9 +100,6 @@ HashNode* HT_Find (const HashTable* T, const void* Key) return 0; } - /* Generate the hash over the index */ - Hash = T->Func->GenHash (Key); - /* Search for the entry in the given chain */ N = T->Table[Hash % T->Slots]; while (N) { @@ -96,7 +108,7 @@ HashNode* HT_Find (const HashTable* T, const void* Key) * if it is not really necessary. */ if (N->Hash == Hash && - T->Func->Compare (Key, T->Func->GetKey (N->Entry)) == 0) { + T->Func->Compare (Key, T->Func->GetKey (HN_GetEntry (N))) == 0) { /* Found */ break; } @@ -118,7 +130,7 @@ void* HT_FindEntry (const HashTable* T, const void* Key) HashNode* N = HT_Find (T, Key); /* Convert the node into an entry if necessary */ - return N? N->Entry : 0; + return N? HN_GetEntry (N) : 0; } @@ -134,7 +146,7 @@ void HT_Insert (HashTable* T, HashNode* N) } /* Generate the hash over the node key. */ - N->Hash = T->Func->GenHash (T->Func->GetKey (N->Entry)); + N->Hash = T->Func->GenHash (T->Func->GetKey (HN_GetEntry (N))); /* Calculate the reduced hash */ RHash = N->Hash % T->Slots; @@ -182,7 +194,7 @@ void HT_Walk (HashTable* T, void (*F) (void* Entry, void* Data), void* Data) /* Walk over all entries in this chain */ while (N) { /* Call the user function */ - F (N->Entry, Data); + F (HN_GetEntry (N), Data); /* Next node in chain */ N = N->Next; } diff --git a/src/common/hashtab.h b/src/common/hashtab.h index fb8ece3fa..98b5901c4 100644 --- a/src/common/hashtab.h +++ b/src/common/hashtab.h @@ -109,10 +109,20 @@ INLINE void InitHashNode (HashNode* N, void* Entry) N->Entry = Entry; } #else -#define InitHashNode(N, Entry) \ - (N)->Next = 0; \ - (N)->Owner = 0; \ - (N)->Entry = (Entry) +#define InitHashNode(N, E) \ + (N)->Next = 0, \ + (N)->Owner = 0, \ + (N)->Entry = (E) +#endif + +#if defined(HAVE_INLINE) +INLINE void* HN_GetEntry (HashNode* N) +/* Get the entry from a hash node */ +{ + return N->Entry; +} +#else +#define HN_GetEntry(N) (N)->Entry #endif @@ -175,6 +185,11 @@ void FreeHashTable (HashTable* T); HashNode* HT_Find (const HashTable* T, const void* Key); /* Find the node with the given key*/ +HashNode* HT_FindHash (const HashTable* T, const void* Key, unsigned Hash); +/* Find the node with the given key. Differs from HT_Find in that the hash + * for the key is precalculated and passed to the function. + */ + void* HT_FindEntry (const HashTable* T, const void* Key); /* Find the node with the given key and return the corresponding entry */ diff --git a/src/common/make/watcom.mak b/src/common/make/watcom.mak index 48135854a..346a693ce 100644 --- a/src/common/make/watcom.mak +++ b/src/common/make/watcom.mak @@ -10,7 +10,7 @@ export WATCOM = c:\\watcom export INCLUDE = $(WATCOM)\\h # We will use the windows compiler under linux (define as empty for windows) -WINE = wine -- +WINE = wine -- # Programs AR = $(WINE) WLIB