From 2c26c663cba34d1bd2f615766fb880f2dbfd4497 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 8 Nov 2000 04:33:36 +0000 Subject: [PATCH] fixed SLL iterator performance --- src/libCom/cxxTemplates/resourceLib.h | 22 ++++++++++++++-------- src/libCom/cxxTemplates/tsSLList.h | 8 ++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libCom/cxxTemplates/resourceLib.h b/src/libCom/cxxTemplates/resourceLib.h index c622a2a8e..a31d1fb63 100644 --- a/src/libCom/cxxTemplates/resourceLib.h +++ b/src/libCom/cxxTemplates/resourceLib.h @@ -478,7 +478,6 @@ void resTable::traverse (pSetMFArg(pCB)) const pList = this->pTable; while ( pList < &this->pTable[this->hashIdMask+1] ) { tsSLIter pItem ( pList->first () ); - while ( pItem.valid () ) { T * p = & ( *pItem ); (p->*pCB) (); @@ -594,7 +593,7 @@ resTable::~resTable() // template inline resTableIter::resTableIter (const resTable &tableIn) : - iter (tableIn.pTable[0]), index (1), table (tableIn) {} + iter ( tableIn.pTable[0].first () ), index (1), table ( tableIn ) {} // // resTableIter::next () @@ -602,15 +601,22 @@ inline resTableIter::resTableIter (const resTable &tableIn) : template inline T * resTableIter::next () { - this->iter = this->iter.itemAfter (); if ( this->iter.valid () ) { - return & ( *this->iter ); + T *p = & (*this->iter); + this->iter++; + return p; } - if ( this->index >= (1u<table.hashIdNBits) ) { - return 0; + while ( true ) { + if ( this->index >= (1u<table.hashIdNBits) ) { + return 0; + } + this->iter = tsSLIter ( this->table.pTable[this->index++].first () ); + if ( this->iter.valid () ) { + T *p = & (*this->iter); + this->iter++; + return p; + } } - this->iter = tsSLIter ( this->table.pTable[this->index++].first () ); - return & ( *this->iter ); } // diff --git a/src/libCom/cxxTemplates/tsSLList.h b/src/libCom/cxxTemplates/tsSLList.h index b1bf35f8a..acf54a3fd 100644 --- a/src/libCom/cxxTemplates/tsSLList.h +++ b/src/libCom/cxxTemplates/tsSLList.h @@ -46,7 +46,7 @@ // template < class T > class tsSLList; template < class T > class tsSLIter; -template < class T > class tsSLIterRm; +template < class T > class tsSLIterConst; // // tsSLNode @@ -56,7 +56,7 @@ template class tsSLNode { friend class tsSLList < T >; friend class tsSLIter < T >; -friend class tsSLIterRm < T >; +friend class tsSLIterConst < T >; public: tsSLNode (); void operator = ( const tsSLNode < T > & ) const; @@ -328,7 +328,7 @@ inline const T * tsSLIterConst::operator -> () const template < class T > inline tsSLIterConst tsSLIterConst::operator ++ () // prefix ++ { - tsSLNode < T > *pCurNode = this->pConstEntry; + const tsSLNode < T > *pCurNode = this->pConstEntry; this->pConstEntry = pCurNode->pNext; return *this; } @@ -426,7 +426,7 @@ inline tsSLIter tsSLIter::operator ++ () // prefix ++ template < class T > inline tsSLIter tsSLIter::operator ++ (int) // postfix ++ { - tsSLIterConst tmp = *this; + tsSLIter tmp = *this; this->tsSLIterConst::operator ++ (); return tmp; }