]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Optimization of the iterator "++": omitting of "indexOf" calling for the list of... V6_5_0b1
authormpv <mpv@opencascade.com>
Fri, 4 May 2012 07:59:57 +0000 (07:59 +0000)
committermpv <mpv@opencascade.com>
Fri, 4 May 2012 07:59:57 +0000 (07:59 +0000)
src/SUIT/SUIT_DataObjectIterator.cxx
src/SUIT/SUIT_DataObjectIterator.h

index 971bdfe6ba6a3027987acd1bb25c195dc4a5f878..a91ff24583484d9a216d4d15157b4f482f2f27f7 100644 (file)
@@ -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();
 }
 
 /*!
index d3ed4783b44985606133069f15987c6f3f75810d..360a816c158b21106b731b2c03ee6f6036822e7c 100644 (file)
@@ -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<int>        myChildrenIndexes;
 };
 
 /*!