From f18c7b8959a93af4ffbb260a2a3e676090de8aea Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 9 Aug 2013 22:41:36 -0500 Subject: [PATCH] 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.) --- src/dobjtype.cpp | 25 +++++++++++++++++++++---- src/dobjtype.h | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index f8a4a8c88..92e37333a 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -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 *a2 = (const TArray *)p2; + const TArray *a3 = (const TArray *)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; + } } //========================================================================== diff --git a/src/dobjtype.h b/src/dobjtype.h index 01653c847..e3fb2603a 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -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); };