Make relayout temperal vector as member.
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.cpp
index c32cebe..2d639f5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
  */
 
 // CLASS HEADER
-#include "relayout-controller-impl.h"
+#include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
 
 // EXTERNAL INCLUDES
 #if defined(DEBUG_ENABLED)
@@ -119,12 +119,11 @@ RelayoutController::RelayoutController(Integration::RenderController& controller
 {
   // Make space for 32 controls to avoid having to copy construct a lot in the beginning
   mRelayoutStack->Reserve(32);
+  mPotentialRedundantSubRoots.reserve(32);
+  mTopOfSubTreeStack.reserve(32);
 }
 
-RelayoutController::~RelayoutController()
-{
-  delete mRelayoutStack;
-}
+RelayoutController::~RelayoutController() = default;
 
 RelayoutController* RelayoutController::Get()
 {
@@ -155,8 +154,11 @@ void RelayoutController::RequestRelayout(Dali::Actor& actor, Dimension::Type dim
     return;
   }
 
-  std::vector<Dali::Actor> potentialRedundantSubRoots;
-  std::vector<Dali::Actor> topOfSubTreeStack;
+  std::vector<Dali::Actor>& potentialRedundantSubRoots = mPotentialRedundantSubRoots;
+  std::vector<Dali::Actor>& topOfSubTreeStack          = mTopOfSubTreeStack;
+
+  DALI_ASSERT_ALWAYS(potentialRedundantSubRoots.empty() && "potentialRedundantSubRoots must be empty before RequestRelayout!");
+  DALI_ASSERT_ALWAYS(topOfSubTreeStack.empty() && "topOfSubTreeStack must be empty before RequestRelayout!");
 
   topOfSubTreeStack.push_back(actor);
 
@@ -197,6 +199,8 @@ void RelayoutController::RequestRelayout(Dali::Actor& actor, Dimension::Type dim
     RemoveRequest(subRoot);
   }
 
+  potentialRedundantSubRoots.clear();
+
   if(!mProcessingCoreEvents)
   {
     mRenderController.RequestProcessEventsOnIdle(false);
@@ -372,9 +376,9 @@ void RelayoutController::AddRequest(Dali::Actor& actor)
   Internal::Actor* actorPtr = &GetImplementation(actor);
 
   // Only add the rootActor if it is not already recorded
-  auto itr = std::find(mDirtyLayoutSubTrees.begin(), mDirtyLayoutSubTrees.end(), actorPtr);
+  auto iter = mDirtyLayoutSubTrees.Find(actorPtr);
 
-  if(itr == mDirtyLayoutSubTrees.end())
+  if(iter == mDirtyLayoutSubTrees.End())
   {
     mDirtyLayoutSubTrees.PushBack(actorPtr);
   }
@@ -383,11 +387,7 @@ void RelayoutController::AddRequest(Dali::Actor& actor)
 void RelayoutController::RemoveRequest(Dali::Actor& actor)
 {
   Internal::Actor* actorPtr = &GetImplementation(actor);
-
-  mDirtyLayoutSubTrees.Erase(std::remove(mDirtyLayoutSubTrees.begin(),
-                                         mDirtyLayoutSubTrees.end(),
-                                         actorPtr),
-                             mDirtyLayoutSubTrees.end());
+  mDirtyLayoutSubTrees.EraseObject(actorPtr);
 }
 
 void RelayoutController::Request()
@@ -404,8 +404,7 @@ void RelayoutController::Request()
 
 void RelayoutController::OnObjectDestroyed(const Dali::RefObject* object)
 {
-  // Search for and null the object if found in the following lists
-  FindAndZero(mDirtyLayoutSubTrees, object);
+  mDirtyLayoutSubTrees.EraseObject(static_cast<const Dali::Internal::Actor*>(object));
 }
 
 void RelayoutController::Relayout()
@@ -446,7 +445,8 @@ void RelayoutController::Relayout()
       {
         Dali::Actor actor;
         Vector2     size;
-        mRelayoutStack->Get(mRelayoutStack->Size() - 1, actor, size);
+
+        mRelayoutStack->GetBack(actor, size);
         Actor& actorImpl = GetImplementation(actor);
         mRelayoutStack->PopBack();
 
@@ -487,18 +487,6 @@ void RelayoutController::SetProcessingCoreEvents(bool processingEvents)
   mProcessingCoreEvents = processingEvents;
 }
 
-void RelayoutController::FindAndZero(const RawActorList& list, const Dali::RefObject* object)
-{
-  // Object has been destroyed so clear it from this list
-  for(auto& actor : list)
-  {
-    if(actor && (actor == object))
-    {
-      actor = nullptr; // Reset the pointer in the list. We don't want to remove it in case something is iterating over the list.
-    }
-  }
-}
-
 uint32_t RelayoutController::GetMemoryPoolCapacity()
 {
   return mRelayoutInfoAllocator.GetCapacity();