From 82025cc2d713d17a71e97a00d94bf07a4a6d6509 Mon Sep 17 00:00:00 2001 From: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com> Date: Sat, 2 Aug 2025 03:42:42 +0300 Subject: [PATCH] Update CUtlMemoryBlockAllocator & CUtlSymbolTableLarge --- public/tier1/memblockallocator.h | 10 +++--- public/tier1/utlsymbollarge.h | 61 +++++++++++--------------------- 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/public/tier1/memblockallocator.h b/public/tier1/memblockallocator.h index 7d86df57..06de730a 100644 --- a/public/tier1/memblockallocator.h +++ b/public/tier1/memblockallocator.h @@ -93,9 +93,9 @@ public: { unsigned int MemoryLeft() const { return m_nTotalSize - m_nUsedSize; } - unsigned int m_nTotalSize; - unsigned int m_nUsedSize; - T *m_pMemory; + unsigned int m_nTotalSize = 0; + unsigned int m_nUsedSize = 0; + T *m_pMemory = nullptr; }; typedef CUtlLeanVector MemPagesVec_t; @@ -108,8 +108,6 @@ public: bool m_unk002; }; -constexpr int a = sizeof(CUtlMemoryBlockAllocator::MemPagesVec_t); - template inline void CUtlMemoryBlockAllocator::RemoveAll( size_t nSize ) { @@ -226,7 +224,7 @@ inline void CUtlMemoryBlockAllocator::SetPageSize( uint32 nPageSize, uint3 m_nPageOffsetBits = largest_bit; } - m_MemPages.SetCount( 1 << (32 - m_nPageOffsetBits) ); + m_MemPages.EnsureCapacity( MaxPossiblePageSize() ); } template diff --git a/public/tier1/utlsymbollarge.h b/public/tier1/utlsymbollarge.h index 203e5c20..0a2d481b 100644 --- a/public/tier1/utlsymbollarge.h +++ b/public/tier1/utlsymbollarge.h @@ -155,57 +155,32 @@ private: unsigned int HashValue( UtlSymLargeId_t id ) const; struct UtlSymTableLargeAltKey - { + { + operator UtlSymLargeId_t() const { return m_SymId; } + const CUtlSymbolTableLargeBase* m_pTable; - const char* m_pString; - int m_nLength; + union + { + struct + { + const char *m_pString; + int m_nLength; + }; + + UtlSymLargeId_t m_SymId; + }; }; 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 { 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 { - 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 { const char* pString = a.m_pTable->String( b ); @@ -227,7 +202,7 @@ private: }; typedef CUtlHashtable Hashtable_t; - typedef CUtlLeanVector< MemBlockHandle_t > MemBlocksVec_t; + typedef CUtlLeanVector< MemBlockHandle_t, int > MemBlocksVec_t; Hashtable_t m_HashTable; MemBlocksVec_t m_MemBlocks; @@ -279,13 +254,17 @@ inline CUtlSymbolLarge CUtlSymbolTableLargeBase< CASEINSENSITIVE, PAGE_SIZE, MUT entry->m_Hash = hash; char *pText = (char *)&entry->m_String[ 0 ]; - memcpy( pText, pString, nLength ); + V_memmove( pText, pString, nLength ); pText[ nLength ] = '\0'; UtlSymLargeId_t id = m_MemBlocks.AddToTail( block + sizeof( LargeSymbolTableHashDecoration_t ) ); + UtlSymTableLargeAltKey key; + key.m_pTable = this; + key.m_SymId = id; + empty_t empty; - m_HashTable.Insert( id, empty, hash ); + m_HashTable.Insert( key, empty, hash ); return entry->ToSymbol(); }