diff --git a/public/tier1/utllinkedlist.h b/public/tier1/utllinkedlist.h index 73538c27..501ba647 100644 --- a/public/tier1/utllinkedlist.h +++ b/public/tier1/utllinkedlist.h @@ -16,6 +16,7 @@ #include "tier0/basetypes.h" #include "utlmemory.h" #include "utlfixedmemory.h" +#include "utlleanvector.h" #include "utlblockmemory.h" #include "tier0/dbg.h" @@ -57,7 +58,7 @@ private: // in memory, but always operate on 32's or 64's in local scope. // The ideal parameter order would be TSMI (you are more likely to override M than I) // but since M depends on I we can't have the defaults in that order, alas. -template , I > > +template , I > > class CUtlLinkedList { public: @@ -130,9 +131,9 @@ public: inline static size_t ElementSize() { return sizeof( ListElem_t ); } // list statistics - int Count() const; - I MaxElementIndex() const; - I NumAllocated( void ) const { return m_NumAlloced; } + int Count() const { return m_Memory.Count(); } + I MaxElementIndex() const { return m_Memory.NumAllocated(); } + I NumAllocated( void ) const { return m_Memory.NumAllocated(); } // Traversing the list I Head() const; @@ -164,8 +165,6 @@ protected: I m_Head; I m_Tail; I m_FirstFree; - I m_ElementCount; // The number actually in the list - I m_NumAlloced; // The number of allocated elements typename M::Iterator_t m_LastAlloc; // the last index allocated FORCEINLINE M const &Memory( void ) const @@ -238,8 +237,7 @@ void CUtlLinkedList::ConstructList() m_Head = InvalidIndex(); m_Tail = InvalidIndex(); m_FirstFree = InvalidIndex(); - m_ElementCount = 0; - m_NumAlloced = 0; + m_Memory.RemoveAll(); } @@ -271,26 +269,6 @@ inline T const& CUtlLinkedList::operator[]( I i ) const return m_Memory[i].m_Element; } -//----------------------------------------------------------------------------- -// list statistics -//----------------------------------------------------------------------------- - -template -inline int CUtlLinkedList::Count() const -{ -#ifdef MULTILIST_PEDANTIC_ASSERTS - AssertMsg( !ML, "CUtlLinkedList::Count() is meaningless for linked lists." ); -#endif - return m_ElementCount; -} - -template -inline I CUtlLinkedList::MaxElementIndex() const -{ - return m_Memory.NumAllocated(); -} - - //----------------------------------------------------------------------------- // Traversing the list //----------------------------------------------------------------------------- @@ -411,7 +389,6 @@ void CUtlLinkedList::Purge() m_Memory.Purge(); m_FirstFree = InvalidIndex(); - m_NumAlloced = 0; //Routing "m_LastAlloc = m_Memory.InvalidIterator();" through a local const to sidestep an internal compiler error on 360 builds const typename M::Iterator_t scInvalidIterator = m_Memory.InvalidIterator(); @@ -448,6 +425,8 @@ I CUtlLinkedList::AllocInternal( bool multilist ) { Assert( m_Memory.IsValidIterator( m_LastAlloc ) || m_ElementCount == 0 ); + m_Memory.AddToTailGetPtr(); + typename M::Iterator_t it = m_Memory.IsValidIterator( m_LastAlloc ) ? m_Memory.Next( m_LastAlloc ) : m_Memory.First(); if ( !m_Memory.IsValidIterator( it ) ) @@ -474,7 +453,6 @@ I CUtlLinkedList::AllocInternal( bool multilist ) m_LastAlloc = it; elem = m_Memory.GetIndex( m_LastAlloc ); - m_NumAlloced++; } else { @@ -716,7 +694,6 @@ void CUtlLinkedList::RemoveAll() // Clear everything else out m_Head = InvalidIndex(); m_Tail = InvalidIndex(); - m_ElementCount = 0; } @@ -762,9 +739,6 @@ void CUtlLinkedList::LinkBefore( I before, I elem ) m_Head = elem; else InternalElement(newElem_mPrevious).m_Next = elem; - - // one more element baby - ++m_ElementCount; } template @@ -801,9 +775,6 @@ void CUtlLinkedList::LinkAfter( I after, I elem ) m_Tail = elem; else InternalElement(newElem.m_Next).m_Previous = elem; - - // one more element baby - ++m_ElementCount; } template @@ -839,9 +810,6 @@ void CUtlLinkedList::Unlink( I elem ) // This marks this node as not in the list, // but not in the free list either pOldElem->m_Previous = pOldElem->m_Next = elem; - - // One less puppy - --m_ElementCount; } }