diff --git a/public/tier1/keyvalues3.h b/public/tier1/keyvalues3.h index f1af81f1..443a9827 100644 --- a/public/tier1/keyvalues3.h +++ b/public/tier1/keyvalues3.h @@ -653,7 +653,6 @@ private: void Free( bool bClearingContext = false ); void ResolveUnspecified(); void PrepareForType( KV3TypeEx_t type, KV3SubType_t subtype ); - void OnClearContext(); void CopyFrom( const KeyValues3* pSrc ); int GetClusterElement() const { return m_nClusterElement; } @@ -735,7 +734,7 @@ public: static const size_t DATA_ALIGNMENT = KV3Helpers::PackAlignOf(); CKeyValues3Array( int cluster_elem = -1, int alloc_size = DATA_SIZE ); - ~CKeyValues3Array() { PurgeBuffers(); } + ~CKeyValues3Array() { Free(); } int GetClusterElement() const { return m_nClusterElement; } void SetClusterElement( int element ) { m_nClusterElement = element; } @@ -757,8 +756,8 @@ public: void CopyFrom( KeyValues3 *parent, const CKeyValues3Array* pSrc ); void RemoveMultiple( KeyValues3 *parent, int from, int num ); - void OnClearContext() { PurgeContent( nullptr, true ); } - void PurgeContent( KeyValues3 *parent = nullptr, bool clearing_context = false ); + void Free( bool clearing_context = false ) { PurgeBuffers(); } + void PurgeContent( KeyValues3 *parent, bool clearing_context = false ); void PurgeBuffers(); static constexpr size_t TotalSizeOf( int initial_size ) { return ALIGN_VALUE( TotalSizeWithoutStaticData() + TotalSizeOfData( MAX( initial_size, 0 ) ), 8 ); } @@ -807,7 +806,7 @@ public: static const size_t DATA_ALIGNMENT = KV3Helpers::PackAlignOf(); CKeyValues3Table( int cluster_elem = -1, int alloc_size = DATA_SIZE ); - ~CKeyValues3Table() { PurgeBuffers(); } + ~CKeyValues3Table() { Free(); } int GetClusterElement() const { return m_nClusterElement; } void SetClusterElement( int element ) { m_nClusterElement = element; } @@ -833,8 +832,8 @@ public: void RemoveMember( KeyValues3 *parent, KV3MemberId_t id ); void RemoveAll( KeyValues3 *parent, int new_size = 0 ); - void OnClearContext() { PurgeContent( nullptr, true ); } - void PurgeContent( KeyValues3 *parent = nullptr, bool bClearingContext = false ); + void Free( bool clearing_context = false ) { PurgeBuffers(); } + void PurgeContent( KeyValues3 *parent, bool bClearingContext = false ); void PurgeBuffers(); static constexpr size_t TotalSizeOf( int initial_size ) { return ALIGN_VALUE( TotalSizeWithoutStaticData() + TotalSizeOfData( MAX( initial_size, 0 ) ), 8 ); } @@ -1391,11 +1390,7 @@ inline void CKeyValues3ClusterImpl::Free( int element, bool clearing_co Assert( element >= 0 && element < NumAllocated() ); Node *node = &m_Values[element]; - - if(clearing_context) - node->m_Value.OnClearContext(); - else - Destruct( &node->m_Value ); + node->m_Value.Free( clearing_context ); m_nElementCount--; @@ -1422,7 +1417,7 @@ inline void CKeyValues3ClusterImpl::InitNodes() template inline void CKeyValues3ClusterImpl::PurgeNodes( bool clearing_context ) { - CVarBitVec free_nodes( NumAllocated() * BITS_PER_INT ); + CVarBitVec free_nodes( NumAllocated() ); for(auto iter = GetNextFree(); iter; iter = iter->m_pNextFree) { @@ -1458,7 +1453,7 @@ inline int CKeyValues3ClusterImpl::GetNodeIndex( NodeType *element ) co template inline void CKeyValues3ClusterImpl::Purge() { - PurgeNodes( false ); + PurgeNodes( true ); PurgeMetaData(); } @@ -1649,8 +1644,10 @@ inline void CKeyValues3Context::ClearClusterNodeChain( ClusterNodeChain template inline void CKeyValues3Context::MoveToPartial( ClusterNodeChain &full_cluster, ClusterNodeChain &partial_cluster ) { - for(auto node = full_cluster.m_pTail; node; node = node->GetPrev()) + CLUSTER *prev; + for(auto node = full_cluster.m_pTail; node; node = prev) { + prev = node->GetPrev(); partial_cluster.AddToChain( node ); } diff --git a/tier1/keyvalues3.cpp b/tier1/keyvalues3.cpp index eceb985a..49788cf2 100644 --- a/tier1/keyvalues3.cpp +++ b/tier1/keyvalues3.cpp @@ -261,7 +261,7 @@ void KeyValues3::Free( bool bClearingContext ) } case KV3_TYPEEX_ARRAY: { - FreeArray( m_Data.m_pArray ); + FreeArray( m_Data.m_pArray, bClearingContext ); m_bFreeArrayMemory = false; m_Data.m_pArray = nullptr; @@ -270,7 +270,7 @@ void KeyValues3::Free( bool bClearingContext ) } case KV3_TYPEEX_TABLE: { - FreeTable( m_Data.m_pTable ); + FreeTable( m_Data.m_pTable, bClearingContext ); m_bFreeArrayMemory = false; m_Data.m_pTable = nullptr; @@ -369,13 +369,6 @@ void KeyValues3::PrepareForType( KV3TypeEx_t type, KV3SubType_t subtype ) m_SubType = subtype; } -void KeyValues3::OnClearContext() -{ - Free( true ); - m_TypeEx = KV3_TYPEEX_NULL; - m_Data.m_nMemory = 0; -} - CKeyValues3Cluster* KeyValues3::GetCluster() const { if ( m_bContextIndependent )