Skip to content

Commit d3b08d6

Browse files
committed
Some small optimizations from Steam branch
Validation changes are irrelevant since we will never compile this code with DBGFLAG_VALIDATE, but it's just nice to get the files more in sync. P4:6571374
1 parent 48cb63e commit d3b08d6

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/public/tier1/utllinkedlist.h

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class CUtlLinkedList
150150

151151
#ifdef DBGFLAG_VALIDATE
152152
void Validate( CValidator &validator, const char *pchName ); // Validate our internal structures
153+
void RecursiveValidate( CValidator &validator, const char *pchName ); // Validate our internal structures
153154
void ValidateSelfAndElements( CValidator &validator, const char *pchName );
154155
#endif // DBGFLAG_VALIDATE
155156

@@ -328,14 +329,14 @@ inline I CUtlLinkedList<T,I>::Next( I i ) const
328329
template <class T, class I>
329330
inline bool CUtlLinkedList<T,I>::IsValidIndex( I i ) const
330331
{
331-
return (i < m_TotalElements) && (i >= 0) &&
332+
return ((unsigned)i < (unsigned)m_TotalElements) &&
332333
((m_Memory[i].m_Previous != i) || (m_Memory[i].m_Next == i));
333334
}
334335

335336
template <class T, class I>
336337
inline bool CUtlLinkedList<T,I>::IsInList( I i ) const
337338
{
338-
return (i < m_TotalElements) && (i >= 0) && (Previous(i) != i);
339+
return ((unsigned)i < (unsigned)m_TotalElements) && (m_Memory[i].m_Previous != i);
339340
}
340341

341342
//-----------------------------------------------------------------------------
@@ -430,7 +431,11 @@ inline I CUtlLinkedList<T,I>::Alloc( bool multilist )
430431
template <class T, class I>
431432
inline void CUtlLinkedList<T,I>::Free( I elem )
432433
{
433-
Assert( IsValidIndex(elem) );
434+
if ( !IsValidIndex(elem) )
435+
{
436+
AssertMsg1( false, "Invalid index %u", (unsigned)elem );
437+
return;
438+
}
434439
Unlink(elem);
435440

436441
ListElem_t &internalElem = InternalElement(elem);
@@ -519,7 +524,7 @@ inline I CUtlLinkedList<T,I>::InsertBefore( I before, T const& src )
519524
LinkBefore( before, newNode );
520525

521526
// Construct the data
522-
CopyConstruct( &Element(newNode), src );
527+
Construct( &Element(newNode), src );
523528

524529
return newNode;
525530
}
@@ -534,7 +539,7 @@ inline I CUtlLinkedList<T,I>::InsertAfter( I after, T const& src )
534539
LinkAfter( after, newNode );
535540

536541
// Construct the data
537-
CopyConstruct( &Element(newNode), src );
542+
Construct( &Element(newNode), src );
538543

539544
return newNode;
540545
}
@@ -722,7 +727,6 @@ inline void CUtlLinkedList<T,I>::LinkAfter( I after, I elem )
722727
template <class T, class I>
723728
inline void CUtlLinkedList<T,I>::Unlink( I elem )
724729
{
725-
Assert( IsValidIndex(elem) );
726730
if (IsInList(elem))
727731
{
728732
ListElem_t *pBase = m_Memory.Base();
@@ -757,6 +761,10 @@ inline void CUtlLinkedList<T,I>::Unlink( I elem )
757761
// One less puppy
758762
--m_ElementCount;
759763
}
764+
else
765+
{
766+
Assert( IsValidIndex(elem) );
767+
}
760768
}
761769

762770
template <class T, class I>
@@ -776,25 +784,27 @@ inline void CUtlLinkedList<T,I>::LinkToTail( I elem )
776784
template <class T, class I>
777785
inline void CUtlLinkedList<T, I>::Validate( CValidator &validator, const char *pchName )
778786
{
779-
#ifdef _WIN32
780-
validator.Push( typeid(*this).raw_name(), this, pchName );
781-
#else
782-
validator.Push( typeid(*this).name(), this, pchName );
783-
#endif
787+
VALIDATE_SCOPE();
784788

785789
m_Memory.Validate( validator, "m_Memory" );
790+
}
786791

787-
validator.Pop();
792+
template <class T, class I>
793+
inline void CUtlLinkedList<T, I>::RecursiveValidate( CValidator &validator, const char *pchName )
794+
{
795+
VALIDATE_SCOPE();
796+
797+
ValidateRecursive( m_Memory );
798+
FOR_EACH_LL( *this, i )
799+
{
800+
ValidateRecursive( Element( i ) );
801+
}
788802
}
789803

790804
template <class T, class I>
791805
inline void CUtlLinkedList<T, I>::ValidateSelfAndElements( CValidator &validator, const char *pchName )
792806
{
793-
#ifdef _WIN32
794-
validator.Push( typeid(*this).raw_name(), this, pchName );
795-
#else
796-
validator.Push( typeid(*this).name(), this, pchName );
797-
#endif
807+
VALIDATE_SCOPE();
798808

799809
m_Memory.Validate( validator, "m_Memory" );
800810

@@ -804,8 +814,6 @@ inline void CUtlLinkedList<T, I>::ValidateSelfAndElements( CValidator &validator
804814
{
805815
functor( Element(i), pchName );
806816
}
807-
808-
validator.Pop();
809817
}
810818

811819
#endif // DBGFLAG_VALIDATE

0 commit comments

Comments
 (0)