1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 12:06:07 +08:00

Update CUtlMemoryBlockAllocator & CUtlSymbolTableLarge

This commit is contained in:
GAMMACASE
2025-08-02 03:42:42 +03:00
parent be67203ef4
commit 82025cc2d7
2 changed files with 24 additions and 47 deletions

View File

@ -93,9 +93,9 @@ public:
{ {
unsigned int MemoryLeft() const { return m_nTotalSize - m_nUsedSize; } unsigned int MemoryLeft() const { return m_nTotalSize - m_nUsedSize; }
unsigned int m_nTotalSize; unsigned int m_nTotalSize = 0;
unsigned int m_nUsedSize; unsigned int m_nUsedSize = 0;
T *m_pMemory; T *m_pMemory = nullptr;
}; };
typedef CUtlLeanVector<MemPage_t, int> MemPagesVec_t; typedef CUtlLeanVector<MemPage_t, int> MemPagesVec_t;
@ -108,8 +108,6 @@ public:
bool m_unk002; bool m_unk002;
}; };
constexpr int a = sizeof(CUtlMemoryBlockAllocator<byte>::MemPagesVec_t);
template<class T, class A> template<class T, class A>
inline void CUtlMemoryBlockAllocator<T, A>::RemoveAll( size_t nSize ) inline void CUtlMemoryBlockAllocator<T, A>::RemoveAll( size_t nSize )
{ {
@ -226,7 +224,7 @@ inline void CUtlMemoryBlockAllocator<T, A>::SetPageSize( uint32 nPageSize, uint3
m_nPageOffsetBits = largest_bit; m_nPageOffsetBits = largest_bit;
} }
m_MemPages.SetCount( 1 << (32 - m_nPageOffsetBits) ); m_MemPages.EnsureCapacity( MaxPossiblePageSize() );
} }
template<class T, class A> template<class T, class A>

View File

@ -156,56 +156,31 @@ private:
struct UtlSymTableLargeAltKey struct UtlSymTableLargeAltKey
{ {
operator UtlSymLargeId_t() const { return m_SymId; }
const CUtlSymbolTableLargeBase* m_pTable; const CUtlSymbolTableLargeBase* m_pTable;
union
{
struct
{
const char *m_pString; const char *m_pString;
int m_nLength; int m_nLength;
}; };
UtlSymLargeId_t m_SymId;
};
};
struct UtlSymTableLargeHashFunctor struct UtlSymTableLargeHashFunctor
{ {
ptrdiff_t m_ownerOffset;
UtlSymTableLargeHashFunctor()
{
const ptrdiff_t tableoffset = (uintp)(&((Hashtable_t*)1024)->GetHashRef()) - 1024;
const ptrdiff_t owneroffset = offsetof(CUtlSymbolTableLargeBase, m_HashTable) + tableoffset;
m_ownerOffset = -owneroffset;
}
unsigned int operator()( UtlSymTableLargeAltKey k ) const unsigned int operator()( UtlSymTableLargeAltKey k ) const
{ {
return CUtlSymbolLarge_Hash( CASEINSENSITIVE, k.m_pString, k.m_nLength ); return CUtlSymbolLarge_Hash( CASEINSENSITIVE, k.m_pString, k.m_nLength );
} }
unsigned int operator()( UtlSymLargeId_t k ) const
{
const CUtlSymbolTableLargeBase* pTable = (const CUtlSymbolTableLargeBase*)((uintp)this + m_ownerOffset);
return pTable->HashValue( k );
}
}; };
struct UtlSymTableLargeEqualFunctor struct UtlSymTableLargeEqualFunctor
{ {
ptrdiff_t m_ownerOffset;
UtlSymTableLargeEqualFunctor()
{
const ptrdiff_t tableoffset = (uintp)(&((Hashtable_t*)1024)->GetEqualRef()) - 1024;
const ptrdiff_t owneroffset = offsetof(CUtlSymbolTableLargeBase, m_HashTable) + tableoffset;
m_ownerOffset = -owneroffset;
}
bool operator()( UtlSymLargeId_t a, UtlSymLargeId_t b ) const
{
const CUtlSymbolTableLargeBase* pTable = (const CUtlSymbolTableLargeBase*)((uintp)this + m_ownerOffset);
if ( !CASEINSENSITIVE )
return strcmp( pTable->String( a ), pTable->String( b ) ) == 0;
else
return V_stricmp_fast( pTable->String( a ), pTable->String( b ) ) == 0;
}
bool operator()( UtlSymTableLargeAltKey a, UtlSymLargeId_t b ) const bool operator()( UtlSymTableLargeAltKey a, UtlSymLargeId_t b ) const
{ {
const char* pString = a.m_pTable->String( b ); const char* pString = a.m_pTable->String( b );
@ -227,7 +202,7 @@ private:
}; };
typedef CUtlHashtable<UtlSymLargeId_t, empty_t, UtlSymTableLargeHashFunctor, UtlSymTableLargeEqualFunctor, UtlSymTableLargeAltKey> Hashtable_t; typedef CUtlHashtable<UtlSymLargeId_t, empty_t, UtlSymTableLargeHashFunctor, UtlSymTableLargeEqualFunctor, UtlSymTableLargeAltKey> Hashtable_t;
typedef CUtlLeanVector< MemBlockHandle_t > MemBlocksVec_t; typedef CUtlLeanVector< MemBlockHandle_t, int > MemBlocksVec_t;
Hashtable_t m_HashTable; Hashtable_t m_HashTable;
MemBlocksVec_t m_MemBlocks; MemBlocksVec_t m_MemBlocks;
@ -279,13 +254,17 @@ inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUT
entry->m_Hash = hash; entry->m_Hash = hash;
char *pText = (char *)&entry->m_String[ 0 ]; char *pText = (char *)&entry->m_String[ 0 ];
memcpy( pText, pString, nLength ); V_memmove( pText, pString, nLength );
pText[ nLength ] = '\0'; pText[ nLength ] = '\0';
UtlSymLargeId_t id = m_MemBlocks.AddToTail( block + sizeof( LargeSymbolTableHashDecoration_t ) ); UtlSymLargeId_t id = m_MemBlocks.AddToTail( block + sizeof( LargeSymbolTableHashDecoration_t ) );
UtlSymTableLargeAltKey key;
key.m_pTable = this;
key.m_SymId = id;
empty_t empty; empty_t empty;
m_HashTable.Insert( id, empty, hash ); m_HashTable.Insert( key, empty, hash );
return entry->ToSymbol(); return entry->ToSymbol();
} }