From 45d9961a6a86d184248ef84f6a07125b0c224f97 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 16 Aug 2023 08:57:47 +0800 Subject: Use ankerl/unordered_dense as a hashmap implementation (#3036) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Correct namespace for getClockFrequency * missing const * Add missing assignment operator * Remove unused variables * Return correct modified variable * Use stable hash code for file system identity * terse static_assert * Structured binding for map iteration * Make (==) and getHashCode const on many structs * Add ConstIterator for LinkedList * Replace uses of ItemProxy::getValue with Dictionary::at * Extract list of loads from gradientsMap before updating it * Const correctness in type layout * Add unordered_dense hashmap submodule * Use wyhash or getHashCode in slang-hash.h * refactor slang-hash.h * Use ankerl/unordered_dense as a hashmap implementation Notable changes: - The subscript operator returns a reference directly to the value, rather than a lazy ItemProxy (pair of dict pointer and key) slang-profile time (95% over 10 runs): - Before: 6.3913906 (±0.0746) - After: 5.9276123 (±0.0964) * 64 bit hash for strings So they have the same hash as char buffers with the same contents * Narrowing warnings for gcc to match msvc * revert back to c++17 * Correct c++ version for msvc * Use path to unordered_dense which keeps tests happy * Do not assign to and read from map in same expression * Remove redundant map operations in primal-hoist * Split out stable hash functions into slang-stable-hash.h * 64 bit hash by default * regenerate vs projects * Correct return type from HashSetBase::getCount() * correct width for call to Dictionary::reserve * Use stable hash for obfuscated module ids * Signed int for reserve * clearer variable naming * Parameterize Dictionary on hash and equality functors * Allow heterogenous lookup for Dictionary * missing const * Use set over operator[] in some places * Remove unused function * s/at/getValue --- source/core/slang-hex-dump-util.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source/core/slang-hex-dump-util.cpp') diff --git a/source/core/slang-hex-dump-util.cpp b/source/core/slang-hex-dump-util.cpp index bbee0a199..3a78c256a 100644 --- a/source/core/slang-hex-dump-util.cpp +++ b/source/core/slang-hex-dump-util.cpp @@ -28,8 +28,8 @@ static const char s_hex[] = "0123456789abcdef"; SLANG_RETURN_ON_FAIL(helper.write(s_start.begin(), s_start.getLength())); SLANG_RETURN_ON_FAIL(helper.print(" %zu", dataCount)); - const HashCode32 hash = getStableHashCode32((const char*)data, dataCount); - SLANG_RETURN_ON_FAIL(helper.print(" %d\n", int(hash) )); + const StableHashCode32 hash = getStableHashCode32((const char*)data, dataCount); + SLANG_RETURN_ON_FAIL(helper.print(" %d\n", hash.hash )); SLANG_RETURN_ON_FAIL(dump(data, dataCount, maxBytesPerLine, writer)); @@ -216,7 +216,7 @@ static SlangResult _findLine(const UnownedStringSlice& find, UnownedStringSlice& UnownedStringSlice startLine, endLine; SLANG_RETURN_ON_FAIL(findStartAndEndLines(lines, startLine, endLine)); - HashCode32 hash; + StableHashCode32 hash; size_t size; { // Get the size and the hash @@ -228,13 +228,13 @@ static SlangResult _findLine(const UnownedStringSlice& find, UnownedStringSlice& } // Extract the size size = stringToInt(String(slices[1])); - hash = HashCode32(stringToInt(String(slices[2]))); + hash = StableHashCode32{stringToUInt(String(slices[2]))}; } SLANG_RETURN_ON_FAIL(parse(UnownedStringSlice(startLine.end(), endLine.begin()), outBytes)); // Calc the hash - const HashCode32 readHash = getStableHashCode32((const char*)outBytes.begin(), outBytes.getCount()); + const StableHashCode32 readHash = getStableHashCode32((const char*)outBytes.begin(), outBytes.getCount()); if (readHash != hash || size_t(outBytes.getCount()) != size) { -- cgit v1.2.3