1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Correct CKeyValues3Context::Clear/Purge

This commit is contained in:
GAMMACASE
2025-02-25 21:41:37 +03:00
parent 31315b4e82
commit 4465eb0930
2 changed files with 14 additions and 24 deletions

View File

@ -653,7 +653,6 @@ private:
void Free( bool bClearingContext = false ); void Free( bool bClearingContext = false );
void ResolveUnspecified(); void ResolveUnspecified();
void PrepareForType( KV3TypeEx_t type, KV3SubType_t subtype ); void PrepareForType( KV3TypeEx_t type, KV3SubType_t subtype );
void OnClearContext();
void CopyFrom( const KeyValues3* pSrc ); void CopyFrom( const KeyValues3* pSrc );
int GetClusterElement() const { return m_nClusterElement; } int GetClusterElement() const { return m_nClusterElement; }
@ -735,7 +734,7 @@ public:
static const size_t DATA_ALIGNMENT = KV3Helpers::PackAlignOf<Element_t>(); static const size_t DATA_ALIGNMENT = KV3Helpers::PackAlignOf<Element_t>();
CKeyValues3Array( int cluster_elem = -1, int alloc_size = DATA_SIZE ); CKeyValues3Array( int cluster_elem = -1, int alloc_size = DATA_SIZE );
~CKeyValues3Array() { PurgeBuffers(); } ~CKeyValues3Array() { Free(); }
int GetClusterElement() const { return m_nClusterElement; } int GetClusterElement() const { return m_nClusterElement; }
void SetClusterElement( int element ) { m_nClusterElement = element; } void SetClusterElement( int element ) { m_nClusterElement = element; }
@ -757,8 +756,8 @@ public:
void CopyFrom( KeyValues3 *parent, const CKeyValues3Array* pSrc ); void CopyFrom( KeyValues3 *parent, const CKeyValues3Array* pSrc );
void RemoveMultiple( KeyValues3 *parent, int from, int num ); void RemoveMultiple( KeyValues3 *parent, int from, int num );
void OnClearContext() { PurgeContent( nullptr, true ); } void Free( bool clearing_context = false ) { PurgeBuffers(); }
void PurgeContent( KeyValues3 *parent = nullptr, bool clearing_context = false ); void PurgeContent( KeyValues3 *parent, bool clearing_context = false );
void PurgeBuffers(); void PurgeBuffers();
static constexpr size_t TotalSizeOf( int initial_size ) { return ALIGN_VALUE( TotalSizeWithoutStaticData() + TotalSizeOfData( MAX( initial_size, 0 ) ), 8 ); } 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<Hash_t, Member_t, Name_t, Flags_t>(); static const size_t DATA_ALIGNMENT = KV3Helpers::PackAlignOf<Hash_t, Member_t, Name_t, Flags_t>();
CKeyValues3Table( int cluster_elem = -1, int alloc_size = DATA_SIZE ); CKeyValues3Table( int cluster_elem = -1, int alloc_size = DATA_SIZE );
~CKeyValues3Table() { PurgeBuffers(); } ~CKeyValues3Table() { Free(); }
int GetClusterElement() const { return m_nClusterElement; } int GetClusterElement() const { return m_nClusterElement; }
void SetClusterElement( int element ) { m_nClusterElement = element; } void SetClusterElement( int element ) { m_nClusterElement = element; }
@ -833,8 +832,8 @@ public:
void RemoveMember( KeyValues3 *parent, KV3MemberId_t id ); void RemoveMember( KeyValues3 *parent, KV3MemberId_t id );
void RemoveAll( KeyValues3 *parent, int new_size = 0 ); void RemoveAll( KeyValues3 *parent, int new_size = 0 );
void OnClearContext() { PurgeContent( nullptr, true ); } void Free( bool clearing_context = false ) { PurgeBuffers(); }
void PurgeContent( KeyValues3 *parent = nullptr, bool bClearingContext = false ); void PurgeContent( KeyValues3 *parent, bool bClearingContext = false );
void PurgeBuffers(); void PurgeBuffers();
static constexpr size_t TotalSizeOf( int initial_size ) { return ALIGN_VALUE( TotalSizeWithoutStaticData() + TotalSizeOfData( MAX( initial_size, 0 ) ), 8 ); } 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<SIZE, T>::Free( int element, bool clearing_co
Assert( element >= 0 && element < NumAllocated() ); Assert( element >= 0 && element < NumAllocated() );
Node *node = &m_Values[element]; Node *node = &m_Values[element];
node->m_Value.Free( clearing_context );
if(clearing_context)
node->m_Value.OnClearContext();
else
Destruct( &node->m_Value );
m_nElementCount--; m_nElementCount--;
@ -1422,7 +1417,7 @@ inline void CKeyValues3ClusterImpl<SIZE, T>::InitNodes()
template<size_t SIZE, typename T> template<size_t SIZE, typename T>
inline void CKeyValues3ClusterImpl<SIZE, T>::PurgeNodes( bool clearing_context ) inline void CKeyValues3ClusterImpl<SIZE, T>::PurgeNodes( bool clearing_context )
{ {
CVarBitVec free_nodes( NumAllocated() * BITS_PER_INT ); CVarBitVec free_nodes( NumAllocated() );
for(auto iter = GetNextFree(); iter; iter = iter->m_pNextFree) for(auto iter = GetNextFree(); iter; iter = iter->m_pNextFree)
{ {
@ -1458,7 +1453,7 @@ inline int CKeyValues3ClusterImpl<SIZE, T>::GetNodeIndex( NodeType *element ) co
template<size_t SIZE, typename T> template<size_t SIZE, typename T>
inline void CKeyValues3ClusterImpl<SIZE, T>::Purge() inline void CKeyValues3ClusterImpl<SIZE, T>::Purge()
{ {
PurgeNodes( false ); PurgeNodes( true );
PurgeMetaData(); PurgeMetaData();
} }
@ -1649,8 +1644,10 @@ inline void CKeyValues3Context::ClearClusterNodeChain( ClusterNodeChain<CLUSTER>
template<typename CLUSTER> template<typename CLUSTER>
inline void CKeyValues3Context::MoveToPartial( ClusterNodeChain<CLUSTER> &full_cluster, ClusterNodeChain<CLUSTER> &partial_cluster ) inline void CKeyValues3Context::MoveToPartial( ClusterNodeChain<CLUSTER> &full_cluster, ClusterNodeChain<CLUSTER> &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 ); partial_cluster.AddToChain( node );
} }

View File

@ -261,7 +261,7 @@ void KeyValues3::Free( bool bClearingContext )
} }
case KV3_TYPEEX_ARRAY: case KV3_TYPEEX_ARRAY:
{ {
FreeArray( m_Data.m_pArray ); FreeArray( m_Data.m_pArray, bClearingContext );
m_bFreeArrayMemory = false; m_bFreeArrayMemory = false;
m_Data.m_pArray = nullptr; m_Data.m_pArray = nullptr;
@ -270,7 +270,7 @@ void KeyValues3::Free( bool bClearingContext )
} }
case KV3_TYPEEX_TABLE: case KV3_TYPEEX_TABLE:
{ {
FreeTable( m_Data.m_pTable ); FreeTable( m_Data.m_pTable, bClearingContext );
m_bFreeArrayMemory = false; m_bFreeArrayMemory = false;
m_Data.m_pTable = nullptr; m_Data.m_pTable = nullptr;
@ -369,13 +369,6 @@ void KeyValues3::PrepareForType( KV3TypeEx_t type, KV3SubType_t subtype )
m_SubType = subtype; m_SubType = subtype;
} }
void KeyValues3::OnClearContext()
{
Free( true );
m_TypeEx = KV3_TYPEEX_NULL;
m_Data.m_nMemory = 0;
}
CKeyValues3Cluster* KeyValues3::GetCluster() const CKeyValues3Cluster* KeyValues3::GetCluster() const
{ {
if ( m_bContextIndependent ) if ( m_bContextIndependent )