mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 12:06:07 +08:00
Update CUtlLinkedList
This commit is contained in:
@ -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 <class T, class S = unsigned short, bool ML = false, class I = S, class M = CUtlMemory< UtlLinkedListElem_t<T, S>, I > >
|
||||
template <class T, class S = unsigned short, bool ML = false, class I = S, class M = CUtlLeanVector< UtlLinkedListElem_t<T, S>, 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<T,S,ML,I,M>::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<T,S,ML,I,M>::operator[]( I i ) const
|
||||
return m_Memory[i].m_Element;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// list statistics
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <class T, class S, bool ML, class I, class M>
|
||||
inline int CUtlLinkedList<T,S,ML,I,M>::Count() const
|
||||
{
|
||||
#ifdef MULTILIST_PEDANTIC_ASSERTS
|
||||
AssertMsg( !ML, "CUtlLinkedList::Count() is meaningless for linked lists." );
|
||||
#endif
|
||||
return m_ElementCount;
|
||||
}
|
||||
|
||||
template <class T, class S, bool ML, class I, class M>
|
||||
inline I CUtlLinkedList<T,S,ML,I,M>::MaxElementIndex() const
|
||||
{
|
||||
return m_Memory.NumAllocated();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Traversing the list
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -411,7 +389,6 @@ void CUtlLinkedList<T,S,ML,I,M>::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<T,S,ML,I,M>::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<T,S,ML,I,M>::AllocInternal( bool multilist )
|
||||
|
||||
m_LastAlloc = it;
|
||||
elem = m_Memory.GetIndex( m_LastAlloc );
|
||||
m_NumAlloced++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -716,7 +694,6 @@ void CUtlLinkedList<T,S,ML,I,M>::RemoveAll()
|
||||
// Clear everything else out
|
||||
m_Head = InvalidIndex();
|
||||
m_Tail = InvalidIndex();
|
||||
m_ElementCount = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -762,9 +739,6 @@ void CUtlLinkedList<T,S,ML,I,M>::LinkBefore( I before, I elem )
|
||||
m_Head = elem;
|
||||
else
|
||||
InternalElement(newElem_mPrevious).m_Next = elem;
|
||||
|
||||
// one more element baby
|
||||
++m_ElementCount;
|
||||
}
|
||||
|
||||
template <class T, class S, bool ML, class I, class M>
|
||||
@ -801,9 +775,6 @@ void CUtlLinkedList<T,S,ML,I,M>::LinkAfter( I after, I elem )
|
||||
m_Tail = elem;
|
||||
else
|
||||
InternalElement(newElem.m_Next).m_Previous = elem;
|
||||
|
||||
// one more element baby
|
||||
++m_ElementCount;
|
||||
}
|
||||
|
||||
template <class T, class S, bool ML, class I, class M>
|
||||
@ -839,9 +810,6 @@ void CUtlLinkedList<T,S,ML,I,M>::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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user