mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-12 07:34:50 +00:00
Make FType::Hash work for PPrototype
- For Prototypes, Hash is passed the address of two TArrays. If we blindly hash those without checking their contents, then we can forget about ever finding any matching prototypes in the type table. (Not that I remember why I wanted them to be unique, but I'm sure I must have had my reasons.)
This commit is contained in:
parent
93cbdd37a5
commit
f18c7b8959
2 changed files with 22 additions and 5 deletions
|
@ -1646,17 +1646,34 @@ void FTypeTable::AddType(PType *type)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
size_t FTypeTable::Hash(const void *p1, intptr_t p2, intptr_t p3)
|
||||
size_t FTypeTable::Hash(const PClass *p1, intptr_t p2, intptr_t p3)
|
||||
{
|
||||
size_t i1 = (size_t)p1;
|
||||
size_t i2 = (size_t)p2;
|
||||
size_t i3 = (size_t)p3;
|
||||
|
||||
// Swap the high and low halves of i1. The compiler should be smart enough
|
||||
// to transform this into a ROR or ROL.
|
||||
i1 = (i1 >> (sizeof(size_t)*4)) | (i1 << (sizeof(size_t)*4));
|
||||
|
||||
return (~i1 ^ i2) + i3 * 961748927; // i3 is multiplied by a prime
|
||||
if (p1 != RUNTIME_CLASS(PPrototype))
|
||||
{
|
||||
size_t i2 = (size_t)p2;
|
||||
size_t i3 = (size_t)p3;
|
||||
return (~i1 ^ i2) + i3 * 961748927; // i3 is multiplied by a prime
|
||||
}
|
||||
else
|
||||
{ // Prototypes need to hash the TArrays at p2 and p3
|
||||
const TArray<PType *> *a2 = (const TArray<PType *> *)p2;
|
||||
const TArray<PType *> *a3 = (const TArray<PType *> *)p3;
|
||||
for (unsigned i = 0; i < a2->Size(); ++i)
|
||||
{
|
||||
i1 = (i1 * 961748927) + (size_t)((*a2)[i]);
|
||||
}
|
||||
for (unsigned i = 0; i < a3->Size(); ++i)
|
||||
{
|
||||
i1 = (i1 * 961748927) + (size_t)((*a3)[i]);
|
||||
}
|
||||
return i1;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -573,7 +573,7 @@ struct FTypeTable
|
|||
void Mark();
|
||||
void Clear();
|
||||
|
||||
static size_t Hash(const void *p1, intptr_t p2, intptr_t p3);
|
||||
static size_t Hash(const PClass *p1, intptr_t p2, intptr_t p3);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue