From c4615fe0ae7e1849b23e9a96d1453794b0b40e90 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 9 Aug 2023 09:11:23 -0700 Subject: Clean up and improve Val deduplication performance. (#3069) * Clean up and improve Val deuplication performance. * Fix. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-ast-val.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'source/slang/slang-ast-val.cpp') 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(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() -- cgit v1.2.3