From: mpv Date: Fri, 4 May 2012 07:59:57 +0000 (+0000) Subject: Optimization of the iterator "++": omitting of "indexOf" calling for the list of... X-Git-Tag: V6_5_0b1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8e92044718afdfa099596c5f9143955efc110f08;p=modules%2Fgui.git Optimization of the iterator "++": omitting of "indexOf" calling for the list of childred significantly improves performance --- diff --git a/src/SUIT/SUIT_DataObjectIterator.cxx b/src/SUIT/SUIT_DataObjectIterator.cxx index 971bdfe6b..a91ff2458 100644 --- a/src/SUIT/SUIT_DataObjectIterator.cxx +++ b/src/SUIT/SUIT_DataObjectIterator.cxx @@ -27,8 +27,7 @@ */ SUIT_DataObjectIterator::SUIT_DataObjectIterator( SUIT_DataObject* root, const int det, const bool fromTrueRoot ) : myRoot( root ), -myDetourType( det ), -myCurrentLevel( 0 ) +myDetourType( det ) { if ( myRoot && fromTrueRoot ) myRoot = myRoot->root(); @@ -65,7 +64,7 @@ void SUIT_DataObjectIterator::operator++() if ( myCurrent->myChildren.count() > 0 ) { myCurrent = extreme( myCurrent->myChildren, myDetourType == DepthLeft ); - myCurrentLevel++; + myChildrenIndexes.append(myDetourType == DepthLeft ? 0 : myCurrent->myChildren.size() - 1); } else do { @@ -78,18 +77,22 @@ void SUIT_DataObjectIterator::operator++() } else { - int idx = aParent->myChildren.indexOf( myCurrent ); - if ( myDetourType == DepthLeft ) - myCurrent = idx < aParent->myChildren.count() - 1 ? aParent->myChildren[idx + 1] : 0; - else - myCurrent = idx > 0 ? aParent->myChildren[idx - 1] : 0; - if ( !myCurrent ) + int idx = myChildrenIndexes.last(); + if (myDetourType == DepthLeft && idx < aParent->myChildren.count() - 1) { - myCurrent = aParent; - myCurrentLevel--; + myChildrenIndexes.last()++; + myCurrent = aParent->myChildren[idx + 1]; + exit = true; } - else + else if (myDetourType == DepthRight && idx > 0) + { + myChildrenIndexes.last()--; + myCurrent = aParent->myChildren[idx - 1]; exit = true; + } else { + myCurrent = aParent; + myChildrenIndexes.removeLast(); + } } } while ( !exit ); @@ -107,7 +110,7 @@ void SUIT_DataObjectIterator::operator++() { myExtremeChild = extreme( cur->myChildren, myDetourType == BreadthLeft ); myCurrent = myExtremeChild; - myCurrentLevel++; + myChildrenIndexes.append(myDetourType == BreadthLeft ? 0 : myCurrent->myChildren.size() - 1); } } } @@ -130,7 +133,7 @@ SUIT_DataObject* SUIT_DataObjectIterator::current() const */ int SUIT_DataObjectIterator::depth() const { - return myCurrentLevel; + return myChildrenIndexes.size(); } /*! diff --git a/src/SUIT/SUIT_DataObjectIterator.h b/src/SUIT/SUIT_DataObjectIterator.h index d3ed4783b..360a816c1 100644 --- a/src/SUIT/SUIT_DataObjectIterator.h +++ b/src/SUIT/SUIT_DataObjectIterator.h @@ -55,7 +55,9 @@ protected: private: SUIT_DataObject* myExtremeChild; - int myDetourType, myCurrentLevel; + int myDetourType; + ///! Indexes of the iterated children at each level (optimization for avoid indexOf call) + QList myChildrenIndexes; }; /*!