From b1369040c3d6d6a8704bdb17d9de99f36a108e07 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 26 May 2020 13:53:10 -0400 Subject: Improvements around hashing (#1355) * Fields from upper to lower case in slang-ast-decl.h * Lower camel field names in slang-ast-stmt.h * Fix fields in slang-ast-expr.h * slang-ast-type.h make fields lowerCamel. * slang-ast-base.h members functions lowerCamel. * Method names in slang-ast-type.h to lowerCamel. * GetCanonicalType -> getCanonicalType * Substitute -> substitute * Equals -> equals ToString -> toString * ParentDecl -> parentDecl Members -> members * * Make hash code types explicit * Use HashCode as return type of GetHashCode * Added conversion from double to int64_t * Split Stable from other hash functions * toHash32/64 to convert a HashCode to the other styles. GetHashCode32/64 -> getHashCode32/64 GetStableHashCode32/64 -> getStableHashCode32/64 * Other Get/Stable/HashCode32/64 fixes * GetHashCode -> getHashCode * Equals -> equals * CreateCanonicalType -> createCanonicalType * Catches of polymorphic types should be through references otherwise slicing can occur. * Fixes for newer verison of gcc. Fix hashing problem on gcc for Dictionary. * Another fix for GetHashPos * Fix signed issue around GetHashPos --- source/core/slang-riff.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source/core/slang-riff.cpp') diff --git a/source/core/slang-riff.cpp b/source/core/slang-riff.cpp index da547319b..9fc23fbc8 100644 --- a/source/core/slang-riff.cpp +++ b/source/core/slang-riff.cpp @@ -32,7 +32,7 @@ namespace Slang { stream->read(&outChunk, sizeof(RiffHeader)); } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -77,7 +77,7 @@ namespace Slang out->write(end, padSize - payloadSize); } } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -99,7 +99,7 @@ namespace Slang } outReadSize = alignedSize; } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -126,7 +126,7 @@ namespace Slang stream->read(outHeader + 1, headerSize - sizeof(RiffHeader)); } } - catch (IOException&) + catch (const IOException&) { return SLANG_FAIL; } @@ -187,7 +187,7 @@ struct DumpVisitor : public RiffContainer::Visitor _dumpRiffType(data->m_fourCC); m_writer.put(" "); - int hash = data->calcHash(); + const RiffHashCode hash = data->calcHash(); // We don't know in general what the contents is or means... but we can display a hash HexDumpUtil::dump(uint32_t(hash), m_writer.getWriter()); @@ -630,21 +630,21 @@ RiffReadHelper RiffContainer::DataChunk::asReadHelper() const return RiffReadHelper(nullptr, 0); } -int RiffContainer::DataChunk::calcHash() const +RiffHashCode RiffContainer::DataChunk::calcHash() const { - int hash = 0; + RiffHashCode hash = 0; Data* data = m_dataList; while (data) { - // This is a little contrived (in that we don't use the function GetHashCode), but the + // This is a little contrived (in that we don't use the function getHashCode), but the // reason to be careful is we want the same result however many Data blocks there are. const char* buffer = (const char*)data->getPayload(); const size_t size = data->getSize(); for (size_t i = 0; i < size; ++i) { - hash = int(buffer[i]) + (hash << 6) + (hash << 16) - hash; + hash = RiffHashCode(buffer[i]) + (hash << 6) + (hash << 16) - hash; } data = data->m_next; -- cgit v1.2.3