summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-08-16 08:57:47 +0800
committerGitHub <noreply@github.com>2023-08-16 08:57:47 +0800
commit45d9961a6a86d184248ef84f6a07125b0c224f97 (patch)
treec91d9b9aa722ceb727f7f1c8c2041d7d2bb13466 /source/slang/slang.cpp
parente34b005c47d265105e7bba509cadaa3e225237af (diff)
Use ankerl/unordered_dense as a hashmap implementation (#3036)
* 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
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 1edf62a38..71c705246 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -407,11 +407,8 @@ SlangResult Session::saveStdLib(SlangArchiveType archiveType, ISlangBlob** outBl
SLANG_AST_BUILDER_RAII(m_builtinLinkage->getASTBuilder());
- for (auto& pair : m_builtinLinkage->mapNameToLoadedModules)
+ for (const auto& [moduleName, module] : m_builtinLinkage->mapNameToLoadedModules)
{
- const Name* moduleName = pair.key;
- Module* module = pair.value;
-
// Set up options
SerialContainerUtil::WriteOptions options;
@@ -943,10 +940,8 @@ Linkage::Linkage(Session* session, ASTBuilder* astBuilder, Linkage* builtinLinka
// Copy of the built in linkages modules
if (builtinLinkage)
{
- for (const auto& pair : builtinLinkage->mapNameToLoadedModules)
- {
- mapNameToLoadedModules.add(pair.key, pair.value);
- }
+ for (const auto& nameToMod : builtinLinkage->mapNameToLoadedModules)
+ mapNameToLoadedModules.add(nameToMod);
}
{
@@ -1387,10 +1382,10 @@ void Linkage::buildHash(DigestBuilder<SHA1>& builder, SlangInt targetIndex)
}
// Add the preprocessor definitions to the hash
- for (auto& key : preprocessorDefinitions)
+ for (const auto& [defName, defVal] : preprocessorDefinitions)
{
- builder.append(key.key);
- builder.append(key.value);
+ builder.append(defName);
+ builder.append(defVal);
}
// Add the target specified by targetIndex
@@ -2074,9 +2069,9 @@ static void _calcViewInitiatingHierarchy(SourceManager* sourceManager, ViewIniti
// Order all the children, by their raw SourceLocs. This is desirable, so that a trivial traversal
// will traverse children in the order they are initiated in the parent source.
// This assumes they increase in SourceLoc implies an later within a source file - this is true currently.
- for (auto& pair : outHierarchy)
+ for (auto& [_, value] : outHierarchy)
{
- pair.value.sort([](SourceView* a, SourceView* b) -> bool { return a->getInitiatingSourceLoc().getRaw() < b->getInitiatingSourceLoc().getRaw(); });
+ value.sort([](SourceView* a, SourceView* b) -> bool { return a->getInitiatingSourceLoc().getRaw() < b->getInitiatingSourceLoc().getRaw(); });
}
}
@@ -2233,12 +2228,12 @@ void FrontEndCompileRequest::parseTranslationUnit(
// Note! that a adding a define twice will cause an exception in debug builds
// that may be desirable or not...
Dictionary<String, String> combinedPreprocessorDefinitions;
- for(auto& def : getLinkage()->preprocessorDefinitions)
- combinedPreprocessorDefinitions.add(def.key, def.value);
- for(auto& def : preprocessorDefinitions)
- combinedPreprocessorDefinitions.add(def.key, def.value);
- for(auto& def : translationUnit->preprocessorDefinitions)
- combinedPreprocessorDefinitions.add(def.key, def.value);
+ for(const auto& def : getLinkage()->preprocessorDefinitions)
+ combinedPreprocessorDefinitions.add(def);
+ for(const auto& def : preprocessorDefinitions)
+ combinedPreprocessorDefinitions.add(def);
+ for(const auto& def : translationUnit->preprocessorDefinitions)
+ combinedPreprocessorDefinitions.add(def);
// Define standard macros, if not already defined. This style assumes using `#if __SOME_VAR` style, as in
//