From 609211a7492d40e56d896c709fb2591302b0aa2a Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Thu, 27 Aug 2020 12:57:28 +0900 Subject: [PATCH] Improve the logic using Erase-Remove Idiom. instead of erasing each element found and restarting the loop again . first find all element and move them to the end of list and then erase them once using std::erase(std::remove_if()). This will improve the cache locality as this will avoid lot ofpointer chaseing. Also avoids expensing Dali::Vector::end() call. Change-Id: I306de3f017ef23ea7d4d1e6e5202940f84fcf872 --- dali/devel-api/common/owner-container.h | 15 +++++ .../update/animation/scene-graph-animation.cpp | 77 ++++++++++------------ 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/dali/devel-api/common/owner-container.h b/dali/devel-api/common/owner-container.h index 6890656..c8c37d5 100644 --- a/dali/devel-api/common/owner-container.h +++ b/dali/devel-api/common/owner-container.h @@ -86,6 +86,21 @@ public: } /** + * Erases a range of elements.(delete from heap). + */ + Iterator Erase(Iterator first, Iterator last) + { + auto itr = first; + while(itr < last) + { + Delete(*itr); + ++itr; + } + + return Vector::Erase(first, last); + } + + /** * Erase an object from OwnerContainer * @param object to remove */ diff --git a/dali/internal/update/animation/scene-graph-animation.cpp b/dali/internal/update/animation/scene-graph-animation.cpp index aa01b10..10a735f 100644 --- a/dali/internal/update/animation/scene-graph-animation.cpp +++ b/dali/internal/update/animation/scene-graph-animation.cpp @@ -430,60 +430,53 @@ void Animation::UpdateAnimators( BufferIndex bufferIndex, bool bake, bool animat const Vector2 playRange( mPlayRange * mDurationSeconds ); float elapsedSecondsClamped = Clamp( mElapsedSeconds, playRange.x, playRange.y ); + //Remove animators whose PropertyOwner has been destroyed + mAnimators.Erase(std::remove_if(mAnimators.begin(), + mAnimators.end(), + [](auto animator) { return animator->Orphan(); }), + mAnimators.end()); + //Loop through all animators - bool applied(true); - for ( auto&& iter = mAnimators.Begin(); iter != mAnimators.End(); ) + for(auto& animator : mAnimators) { - AnimatorBase *animator = *iter; - - if( animator->Orphan() ) - { - //Remove animators whose PropertyOwner has been destroyed - iter = mAnimators.Erase(iter); - } - else + bool applied(true); + if(animator->IsEnabled()) { - if( animator->IsEnabled() ) - { - const float intervalDelay( animator->GetIntervalDelay() ); + const float intervalDelay(animator->GetIntervalDelay()); - if( elapsedSecondsClamped >= intervalDelay ) + if(elapsedSecondsClamped >= intervalDelay) + { + // Calculate a progress specific to each individual animator + float progress(1.0f); + const float animatorDuration = animator->GetDuration(); + if(animatorDuration > 0.0f) // animators can be "immediate" { - // Calculate a progress specific to each individual animator - float progress(1.0f); - const float animatorDuration = animator->GetDuration(); - if (animatorDuration > 0.0f) // animators can be "immediate" - { - progress = Clamp((elapsedSecondsClamped - intervalDelay) / animatorDuration, 0.0f , 1.0f ); - } - animator->Update(bufferIndex, progress, bake); - - if (animatorDuration > 0.0f && (elapsedSecondsClamped - intervalDelay) <= animatorDuration) - { - mIsActive[bufferIndex] = true; - } + progress = Clamp((elapsedSecondsClamped - intervalDelay) / animatorDuration, 0.0f, 1.0f); } - applied = true; - } - else - { - applied = false; - } + animator->Update(bufferIndex, progress, bake); - if ( animationFinished ) - { - animator->SetActive( false ); + if (animatorDuration > 0.0f && (elapsedSecondsClamped - intervalDelay) <= animatorDuration) + { + mIsActive[bufferIndex] = true; + } } + applied = true; + } + else + { + applied = false; + } - if (applied) - { - INCREASE_COUNTER(PerformanceMonitor::ANIMATORS_APPLIED); - } + if(animationFinished) + { + animator->SetActive(false); + } - ++iter; + if(applied) + { + INCREASE_COUNTER(PerformanceMonitor::ANIMATORS_APPLIED); } } - } } // namespace SceneGraph -- 2.7.4