diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-09 09:11:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-09 09:11:23 -0700 |
| commit | c4615fe0ae7e1849b23e9a96d1453794b0b40e90 (patch) | |
| tree | 0d8d4eed0c90df9664420737d60749f391c11ffb /source/slang/slang-ast-val.cpp | |
| parent | 793a29afc9539f893883b5ad8d88639d63f401e0 (diff) | |
Clean up and improve Val deduplication performance. (#3069)
* Clean up and improve Val deuplication performance.
* Fix.
* Fix.
* Fix.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ast-val.cpp')
| -rw-r--r-- | source/slang/slang-ast-val.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index dd30f8ef6..a0ea60625 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -21,7 +21,7 @@ void ValNodeDesc::init() // to match the semantics implemented for `==` on // `NodeDesc`. // - hasher.hashValue(operands[i].values.nodeOperand); + hasher.hashValue(operands[i].values.intOperand); } hashCode = hasher.getResult(); } @@ -59,13 +59,13 @@ Val* Val::resolve() // If we are not in a proper checking context, just return the previously resolved val. if (!astBuilder) return m_resolvedVal? m_resolvedVal : this; - if (m_resolvedVal && m_resolvedValEpoch == getCurrentASTBuilder()->getEpoch()) + if (m_resolvedVal && m_resolvedValEpoch == astBuilder->getEpoch()) { SLANG_ASSERT(as<Val>(m_resolvedVal)); return m_resolvedVal; } // Update epoch now to avoid infinite recursion. - m_resolvedValEpoch = getCurrentASTBuilder()->getEpoch(); + m_resolvedValEpoch = astBuilder->getEpoch(); m_resolvedVal = resolveImpl(); #ifdef _DEBUG if (m_resolvedVal->_debugUID > 0 && this->_debugUID < 0) @@ -76,16 +76,6 @@ Val* Val::resolve() return m_resolvedVal; } -ValNodeDesc Val::getDesc() -{ - ValNodeDesc desc; - desc.type = astNodeType; - for (auto operand : m_operands) - desc.operands.add(operand); - desc.init(); - return desc; -} - void Val::_setUnique() { m_resolvedVal = this; @@ -115,13 +105,13 @@ Val* Val::defaultResolveImpl() } newDesc.operands.add(operand); } + + if (!diff) + return this; + newDesc.init(); auto astBuilder = getCurrentASTBuilder(); - - Val* existingNode = nullptr; - if (astBuilder->m_cachedNodes.tryGetValue(newDesc, existingNode)) - return existingNode; - return astBuilder->_getOrCreateImpl(newDesc); + return astBuilder->_getOrCreateImpl(_Move(newDesc)); } String Val::toString() |
