Skip to content

Commit

Permalink
Update CKeyValues3Table structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Wend4r committed Dec 20, 2024
1 parent 016ce7d commit c66bb90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
12 changes: 6 additions & 6 deletions public/tier1/keyvalues3.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,9 @@ class CKeyValues3Table

private:
typedef CUtlLeanVectorFixedGrowable<unsigned int, 8, int> HashesVec_t;
typedef CUtlLeanVectorFixedGrowable<KeyValues3*, 8, int> MembersVec_t;
typedef CUtlLeanVectorFixedGrowable<const char*, 8, int> NamesVec_t;
typedef CUtlLeanVectorFixedGrowable<bool, 8, int> IsExternalNameVec_t;
typedef KeyValues3* MembersVec_t;
typedef const char* NamesVec_t;
typedef bool IsExternalNameVec_t;

int m_nClusterElement;

Expand All @@ -554,9 +554,9 @@ class CKeyValues3Table
} *m_pFastSearch;

HashesVec_t m_Hashes;
MembersVec_t m_Members;
NamesVec_t m_Names;
IsExternalNameVec_t m_IsExternalName; // didn't find this used when deleting a table
MembersVec_t m_Members[8];
NamesVec_t m_Names[8];
IsExternalNameVec_t m_IsExternalName[8]; // didn't find this used when deleting a table
bool m_bHasBadNames;
};

Expand Down
27 changes: 6 additions & 21 deletions tier1/keyvalues3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,24 +1379,24 @@ KV3MemberId_t CKeyValues3Table::CreateMember( const CKV3MemberName &name )
if ( m_Hashes.Count() >= 128 && !m_pFastSearch )
EnableFastSearch();

*m_Hashes.AddToTailGetPtr() = name.GetHashCode();
int iNewIndex = m_Hashes.AddToTail(name.GetHashCode());

KV3MemberId_t memberId = m_Hashes.Count() - 1;

CKeyValues3Context* context = GetContext();

if ( context )
{
*m_Members.AddToTailGetPtr() = context->AllocKV();
*m_Names.AddToTailGetPtr() = context->AllocString( name.GetString() );
m_Members[iNewIndex] = context->AllocKV();
m_Names[iNewIndex] = context->AllocString( name.GetString() );
}
else
{
*m_Members.AddToTailGetPtr() = new KeyValues3;
*m_Names.AddToTailGetPtr() = strdup( name.GetString() );
m_Members[iNewIndex] = new KeyValues3;
m_Names[iNewIndex] = strdup( name.GetString() );
}

m_IsExternalName.AddToTail( false );
m_IsExternalName[iNewIndex] = false;

if ( m_pFastSearch && !m_pFastSearch->m_ignore )
m_pFastSearch->m_member_ids.Insert( name.GetHashCode(), memberId );
Expand All @@ -1411,9 +1411,6 @@ void CKeyValues3Table::CopyFrom( const CKeyValues3Table* pSrc )
RemoveAll( nNewSize );

m_Hashes.SetCount( nNewSize );
m_Members.SetCount( nNewSize );
m_Names.SetCount( nNewSize );
m_IsExternalName.SetCount( nNewSize );

CKeyValues3Context* context = GetContext();

Expand Down Expand Up @@ -1457,9 +1454,6 @@ void CKeyValues3Table::RemoveMember( KV3MemberId_t id )
}

m_Hashes.Remove( id );
m_Members.Remove( id );
m_Names.Remove( id );
m_IsExternalName.Remove( id );

if ( m_pFastSearch )
{
Expand Down Expand Up @@ -1487,16 +1481,10 @@ void CKeyValues3Table::RemoveAll( int nAllocSize )
}

m_Hashes.RemoveAll();
m_Members.RemoveAll();
m_Names.RemoveAll();
m_IsExternalName.RemoveAll();

if ( nAllocSize > 0 )
{
m_Hashes.EnsureCapacity( nAllocSize );
m_Members.EnsureCapacity( nAllocSize );
m_Names.EnsureCapacity( nAllocSize );
m_IsExternalName.EnsureCapacity( nAllocSize );
}

if ( m_pFastSearch )
Expand Down Expand Up @@ -1541,9 +1529,6 @@ void CKeyValues3Table::Purge( bool bClearingContext )
m_pFastSearch = NULL;

m_Hashes.Purge();
m_Members.Purge();
m_Names.Purge();
m_IsExternalName.Purge();
}

CKeyValues3Cluster::CKeyValues3Cluster( CKeyValues3Context* context ) :
Expand Down

0 comments on commit c66bb90

Please sign in to comment.