use algorithm and range for 67/243767/3
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Thu, 10 Sep 2020 01:59:09 +0000 (10:59 +0900)
committerDavid Steele <david.steele@samsung.com>
Fri, 23 Oct 2020 11:04:22 +0000 (12:04 +0100)
Change-Id: I8f276553114fecf8c9f6b60696e2dcd274388958

dali/internal/common/core-impl.cpp
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/size-negotiation/relayout-controller-impl.cpp

index fd17bd2..b3b953f 100644 (file)
@@ -248,9 +248,9 @@ void Core::SceneCreated()
 
   mRelayoutController->OnApplicationSceneCreated();
 
-  for( auto iter = mScenes.begin(); iter != mScenes.end(); ++iter )
+  for( const auto& scene : mScenes )
   {
-    Dali::Actor sceneRootLayer = (*iter)->GetRootLayer();
+    Dali::Actor sceneRootLayer = scene->GetRootLayer();
     mRelayoutController->RequestRelayoutTree( sceneRootLayer );
   }
 }
index 75ca77c..d9ba8a1 100755 (executable)
@@ -238,7 +238,7 @@ void EmitVisibilityChangedSignalRecursively( ActorPtr actor, bool visible, Devel
 
     if( actor->GetChildCount() > 0 )
     {
-      for( ActorPtr& child : actor->GetChildrenInternal() )
+      for( auto& child : actor->GetChildrenInternal() )
       {
         EmitVisibilityChangedSignalRecursively( child, visible, DevelActor::VisibilityChange::PARENT );
       }
@@ -516,10 +516,9 @@ ActorPtr Actor::FindChildByName( const std::string& actorName )
   }
   else if( mChildren )
   {
-    ActorIter end = mChildren->end();
-    for( ActorIter iter = mChildren->begin(); iter != end; ++iter )
+    for( const auto& actor : *mChildren )
     {
-      child = (*iter)->FindChildByName( actorName );
+      child = actor->FindChildByName( actorName );
 
       if( child )
       {
@@ -539,10 +538,9 @@ ActorPtr Actor::FindChildById( const uint32_t id )
   }
   else if( mChildren )
   {
-    ActorIter end = mChildren->end();
-    for( ActorIter iter = mChildren->begin(); iter != end; ++iter )
+    for( const auto& actor : *mChildren )
     {
-      child = (*iter)->FindChildById( id );
+      child = actor->FindChildById( id );
 
       if( child )
       {
@@ -1492,10 +1490,9 @@ Actor::~Actor()
   // to guard against GetParent() & Unparent() calls from CustomActor destructors.
   if( mChildren )
   {
-    ActorConstIter endIter = mChildren->end();
-    for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
+    for( const auto& actor : *mChildren )
     {
-      (*iter)->SetParent( nullptr );
+      actor->SetParent( nullptr );
     }
   }
   delete mChildren;
@@ -1539,10 +1536,9 @@ void Actor::ConnectToScene( uint32_t parentDepth )
   RecursiveConnectToScene( connectionList, parentDepth + 1 );
 
   // Notify applications about the newly connected actors.
-  const ActorIter endIter = connectionList.end();
-  for( ActorIter iter = connectionList.begin(); iter != endIter; ++iter )
+  for( const auto& actor : connectionList )
   {
-    (*iter)->NotifyStageConnection();
+    actor->NotifyStageConnection();
   }
 
   RelayoutRequest();
@@ -1566,11 +1562,10 @@ void Actor::RecursiveConnectToScene( ActorContainer& connectionList, uint32_t de
   // Recursively connect children
   if( mChildren )
   {
-    ActorConstIter endIter = mChildren->end();
-    for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
+    for( const auto& actor : *mChildren )
     {
-      (*iter)->SetScene( *mScene );
-      (*iter)->RecursiveConnectToScene( connectionList, depth + 1 );
+      actor->SetScene( *mScene );
+      actor->RecursiveConnectToScene( connectionList, depth + 1 );
     }
   }
 }
@@ -1633,10 +1628,9 @@ void Actor::DisconnectFromStage()
   RecursiveDisconnectFromStage( disconnectionList );
 
   // Notify applications about the newly disconnected actors.
-  const ActorIter endIter = disconnectionList.end();
-  for( ActorIter iter = disconnectionList.begin(); iter != endIter; ++iter )
+  for( const auto& actor : disconnectionList )
   {
-    (*iter)->NotifyStageDisconnection();
+    actor->NotifyStageDisconnection();
   }
 }
 
@@ -1648,10 +1642,9 @@ void Actor::RecursiveDisconnectFromStage( ActorContainer& disconnectionList )
   // Recursively disconnect children
   if( mChildren )
   {
-    ActorConstIter endIter = mChildren->end();
-    for( ActorIter iter = mChildren->begin(); iter != endIter; ++iter )
+    for( const auto& child : *mChildren )
     {
-      (*iter)->RecursiveDisconnectFromStage( disconnectionList );
+      child->RecursiveDisconnectFromStage( disconnectionList );
     }
   }
 
@@ -1742,9 +1735,9 @@ void Actor::DepthTraverseActorTree( OwnerPointer<SceneGraph::NodeDepths>& sceneG
   // Create/add to children of this node
   if( mChildren )
   {
-    for( ActorContainer::iterator it = mChildren->begin(); it != mChildren->end(); ++it )
+    for( const auto& child : *mChildren )
     {
-      Actor* childActor = (*it).Get();
+      Actor* childActor = child.Get();
       ++depthIndex;
       childActor->DepthTraverseActorTree( sceneGraphNodeDepths, depthIndex );
     }
@@ -2243,9 +2236,9 @@ void Actor::NegotiateDimension( Dimension::Type dimension, const Vector2& alloca
     // Check that we havn't gotten into an infinite loop
     ActorDimensionPair searchActor = ActorDimensionPair( this, dimension );
     bool recursionFound = false;
-    for( ActorDimensionStack::iterator it = recursionStack.begin(), itEnd = recursionStack.end(); it != itEnd; ++it )
+    for( auto& element : recursionStack )
     {
-      if( *it == searchActor )
+      if( element == searchActor )
       {
         recursionFound = true;
         break;
@@ -2653,7 +2646,7 @@ void Actor::RaiseToTop()
     ActorContainer& siblings = *(mParent->mChildren);
     if( siblings.back() != this ) // If not already at end
     {
-      ActorContainer::iterator iter = std::find( siblings.begin(), siblings.end(), this );
+      auto iter = std::find( siblings.begin(), siblings.end(), this );
       if( iter != siblings.end() )
       {
         siblings.erase(iter);
@@ -2681,7 +2674,7 @@ void Actor::LowerToBottom()
     {
       ActorPtr thisPtr(this); // ensure this actor remains referenced.
 
-      ActorContainer::iterator iter = std::find( siblings.begin(), siblings.end(), this );
+      auto iter = std::find( siblings.begin(), siblings.end(), this );
       if( iter != siblings.end() )
       {
         siblings.erase(iter);
@@ -2709,8 +2702,8 @@ void Actor::RaiseAbove( Internal::Actor& target )
     {
       ActorPtr thisPtr(this); // ensure this actor remains referenced.
 
-      ActorContainer::iterator targetIter = std::find( siblings.begin(), siblings.end(), &target );
-      ActorContainer::iterator thisIter = std::find( siblings.begin(), siblings.end(), this );
+      auto targetIter = std::find( siblings.begin(), siblings.end(), &target );
+      auto thisIter   = std::find( siblings.begin(), siblings.end(), this );
       if( thisIter < targetIter )
       {
         siblings.erase(thisIter);
@@ -2742,8 +2735,8 @@ void Actor::LowerBelow( Internal::Actor& target )
     {
       ActorPtr thisPtr(this); // ensure this actor remains referenced.
 
-      ActorContainer::iterator targetIter = std::find( siblings.begin(), siblings.end(), &target );
-      ActorContainer::iterator thisIter = std::find( siblings.begin(), siblings.end(), this );
+      auto targetIter = std::find( siblings.begin(), siblings.end(), &target );
+      auto thisIter   = std::find( siblings.begin(), siblings.end(), this );
 
       if( thisIter > targetIter )
       {
@@ -2789,7 +2782,7 @@ void Actor::InheritLayoutDirectionRecursively( ActorPtr actor, Dali::LayoutDirec
 
     if( actor->GetChildCount() > 0 )
     {
-      for( ActorPtr& child : actor->GetChildrenInternal() )
+      for( const auto& child : actor->GetChildrenInternal() )
       {
         InheritLayoutDirectionRecursively( child, direction );
       }
index 33a5245..5f81a1a 100644 (file)
@@ -183,10 +183,8 @@ void RelayoutController::RequestRelayout( Dali::Actor& actor, Dimension::Type di
   }
 
   // Remove any redundant sub-tree heads
-  for( std::vector< Dali::Actor >::iterator it = potentialRedundantSubRoots.begin(), itEnd = potentialRedundantSubRoots.end(); it != itEnd; ++it )
+  for( auto& subRoot : potentialRedundantSubRoots )
   {
-    Dali::Actor subRoot = *it;
-
     RemoveRequest( subRoot );
   }
 
@@ -366,17 +364,9 @@ void RelayoutController::AddRequest( Dali::Actor& actor )
   Internal::Actor* actorPtr = &GetImplementation( actor );
 
   // Only add the rootActor if it is not already recorded
-  bool found = false;
-  for( auto&& item : mDirtyLayoutSubTrees )
-  {
-    if( item == actorPtr )
-    {
-      found = true;
-      break;
-    }
-  }
+  auto itr = std::find( mDirtyLayoutSubTrees.begin(), mDirtyLayoutSubTrees.end(), actorPtr );
 
-  if( !found )
+  if( itr == mDirtyLayoutSubTrees.end() )
   {
     mDirtyLayoutSubTrees.PushBack( actorPtr );
   }
@@ -386,15 +376,10 @@ void RelayoutController::RemoveRequest( Dali::Actor& actor )
 {
   Internal::Actor* actorPtr = &GetImplementation( actor );
 
-  // Remove actor from dirty sub trees
-  for( RawActorList::Iterator it = mDirtyLayoutSubTrees.Begin(), itEnd = mDirtyLayoutSubTrees.End(); it != itEnd; ++it )
-  {
-    if( *it == actorPtr )
-    {
-      mDirtyLayoutSubTrees.Erase( it );
-      break;
-    }
-  }
+  mDirtyLayoutSubTrees.Erase( std::remove( mDirtyLayoutSubTrees.begin(),
+                                           mDirtyLayoutSubTrees.end(),
+                                           actorPtr ),
+                              mDirtyLayoutSubTrees.end() );
 }
 
 void RelayoutController::Request()
@@ -427,10 +412,8 @@ void RelayoutController::Relayout()
 
     // 1. Finds all top-level controls from the dirty list and allocate them the size of the scene
     //    These controls are paired with the parent/scene size and added to the stack.
-    for( RawActorList::Iterator it = mDirtyLayoutSubTrees.Begin(), itEnd = mDirtyLayoutSubTrees.End(); it != itEnd; ++it )
+    for( auto& dirtyActor : mDirtyLayoutSubTrees )
     {
-      Internal::Actor* dirtyActor = *it;
-
       // Need to test if actor is valid (could have been deleted and had the pointer cleared)
       if( dirtyActor )
       {
@@ -502,13 +485,11 @@ void RelayoutController::SetProcessingCoreEvents( bool processingEvents )
 void RelayoutController::FindAndZero( const RawActorList& list, const Dali::RefObject* object )
 {
   // Object has been destroyed so clear it from this list
-  for( RawActorList::Iterator it = list.Begin(), itEnd = list.End(); it != itEnd; ++it )
+  for( auto& actor : list )
   {
-    BaseObject* actor = *it;
-
     if( actor && ( actor == object ) )
     {
-      *it = NULL;    // Reset the pointer in the list. We don't want to remove it in case something is iterating over the list.
+      actor = nullptr; // Reset the pointer in the list. We don't want to remove it in case something is iterating over the list.
     }
   }
 }