Avoid temporary vector creation during Relayout 09/271509/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 22 Feb 2022 07:56:56 +0000 (16:56 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 22 Feb 2022 07:56:56 +0000 (16:56 +0900)
We use temp std::vector stack during NegotiateDimensions.
This patch make we use always same global static value as stack.
So we can avoid create / destroy it every frame.

(This patch is follow up 248736)

Change-Id: I1fa059693d0559b00afbad32dd646e103aba53f7
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/event/actors/actor-sizer.cpp

index 95c6de827f19d2fbf50aebf90acb81461bd3281d..4d8e6d2906c3b864bbd463f777a8aff4cf6a4ecd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -63,6 +63,11 @@ constexpr float GetDimensionValue(const Dali::Vector2& values, const Dali::Dimen
   return 0.0f;
 }
 
+/**
+ * @brief Keep a static recursionstack vector to avoid creating temporary vectors every Relayout().
+ */
+static Dali::Internal::ActorSizer::ActorDimensionStack gRecursionStack{};
+
 } // namespace
 
 namespace Dali::Internal
@@ -776,7 +781,7 @@ void ActorSizer::NegotiateDimension(Dimension::Type dimension, const Vector2& al
     if(!recursionFound)
     {
       // Record the path that we have taken
-      recursionStack.push_back(ActorDimensionPair(&mOwner, dimension));
+      recursionStack.emplace_back(&mOwner, dimension);
 
       // Dimension dependency check
       for(uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i)
@@ -837,14 +842,14 @@ void ActorSizer::NegotiateDimension(Dimension::Type dimension, const Vector2& al
 void ActorSizer::NegotiateDimensions(const Vector2& allocatedSize)
 {
   // Negotiate all dimensions that require it
-  ActorDimensionStack recursionStack;
+  gRecursionStack.clear();
 
   for(uint32_t i = 0; i < Dimension::DIMENSION_COUNT; ++i)
   {
     const Dimension::Type dimension = static_cast<Dimension::Type>(1 << i);
 
     // Negotiate
-    NegotiateDimension(dimension, allocatedSize, recursionStack);
+    NegotiateDimension(dimension, allocatedSize, gRecursionStack);
   }
 }