diff --git a/public/tier1/utlleanvector.h b/public/tier1/utlleanvector.h index 7ac548d6..85e6da20 100644 --- a/public/tier1/utlleanvector.h +++ b/public/tier1/utlleanvector.h @@ -316,7 +316,7 @@ inline CUtlLeanVectorFixedGrowableBase::CUtlLeanVectorFixedGrowableB template< class T, size_t N, class I, class A > inline CUtlLeanVectorFixedGrowableBase::CUtlLeanVectorFixedGrowableBase( T *pMemory, I allocationCount, I numElements ) : - m_nCount( numElements ), m_nAllocated( allocationCount | EXTERNAL_BUFFER_MARKER ), m_pElements( pMemory ) + m_nAllocCount( numElements ), m_nAllocAllocated( allocationCount | EXTERNAL_BUFFER_MARKER ), m_pElements( pMemory ) { } @@ -474,7 +474,10 @@ public: // Is element index valid? bool IsValidIndex( int i ) const; - static int InvalidIndex(); + + // Specify the invalid ('null') index that we'll only return on failure + static const I INVALID_INDEX = (I)-1; // For use with COMPILE_TIME_ASSERT + static I InvalidIndex() { return INVALID_INDEX; } // Adds an element, uses default constructor T* AddToTailGetPtr(); @@ -611,15 +614,6 @@ inline bool CUtlLeanVectorImpl::IsValidIndex( int i ) const return (i >= 0) && (i < this->m_nCount); } -//----------------------------------------------------------------------------- -// Returns in invalid index -//----------------------------------------------------------------------------- -template< class B, class T, class I > -inline int CUtlLeanVectorImpl::InvalidIndex() -{ - return -1; -} - //----------------------------------------------------------------------------- // Adds an element, uses default constructor //----------------------------------------------------------------------------- diff --git a/public/tier1/utllinkedlist.h b/public/tier1/utllinkedlist.h index 501ba647..8ff713c6 100644 --- a/public/tier1/utllinkedlist.h +++ b/public/tier1/utllinkedlist.h @@ -20,6 +20,8 @@ #include "utlblockmemory.h" #include "tier0/dbg.h" +#include + // define to enable asserts griping about things you shouldn't be doing with multilists // #define MULTILIST_PEDANTIC_ASSERTS 1 @@ -41,6 +43,8 @@ template struct UtlLinkedListElem_t { + UtlLinkedListElem_t() {} + T m_Element; I m_Previous; I m_Next; @@ -80,8 +84,6 @@ public: // Make sure we have a particular amount of memory void EnsureCapacity( int num ); - void SetGrowSize( int growSize ); - // Memory deallocation void Purge(); @@ -159,7 +161,7 @@ protected: ListElem_t const& InternalElement( I i ) const { return m_Memory[i]; } // copy constructors not allowed - CUtlLinkedList( CUtlLinkedList const& list ) { Assert(0); } + CUtlLinkedList( CUtlLinkedList const& list ) : m_LastAlloc( 0 ) { Assert(0); } M m_Memory; I m_Head; @@ -370,14 +372,6 @@ void CUtlLinkedList::EnsureCapacity( int num ) m_Memory.EnsureCapacity(num); } -template< class T, class S, bool ML, class I, class M > -void CUtlLinkedList::SetGrowSize( int growSize ) -{ - RemoveAll(); - m_Memory.Init( growSize ); -} - - //----------------------------------------------------------------------------- // Deallocate memory //----------------------------------------------------------------------------- @@ -399,11 +393,14 @@ void CUtlLinkedList::Purge() template void CUtlLinkedList::PurgeAndDeleteElements() { - I iNext; - for( I i=Head(); i != InvalidIndex(); i=iNext ) + if constexpr (std::is_pointer_v) { - iNext = Next(i); - delete Element(i); + I iNext; + for(I i=Head(); i != InvalidIndex(); i=iNext) + { + iNext = Next( i ); + delete Element( i ); + } } Purge(); @@ -432,7 +429,7 @@ I CUtlLinkedList::AllocInternal( bool multilist ) if ( !m_Memory.IsValidIterator( it ) ) { MEM_ALLOC_CREDIT_CLASS(); - m_Memory.Grow(); + m_Memory.AddToTailGetPtr(); it = m_Memory.IsValidIterator( m_LastAlloc ) ? m_Memory.Next( m_LastAlloc ) : m_Memory.First();