From cb58c84dc0eea372d8aa6dcbf8a843415b70638b Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Wed, 8 Sep 2021 06:43:07 -0700 Subject: [PATCH] Use set instead of vector to hold stopped surfaces Summary: changelog: [internal] Use set instead of vector. It makes for nicer API to check if the element exists. Reviewed By: cortinico Differential Revision: D30728211 fbshipit-source-id: 7b7cc1e94bb82a44b064e2945a753adbbce5dc2c --- .../LayoutAnimationKeyFrameManager.cpp | 18 ++++++++---------- .../LayoutAnimationKeyFrameManager.h | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp index 2467b5fa7f7..35a54922e77 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp @@ -340,7 +340,7 @@ bool LayoutAnimationKeyFrameManager::shouldOverridePullTransaction() const { void LayoutAnimationKeyFrameManager::stopSurface(SurfaceId surfaceId) { std::lock_guard lock(surfaceIdsToStopMutex_); - surfaceIdsToStop_.push_back(surfaceId); + surfaceIdsToStop_.insert(surfaceId); } bool LayoutAnimationKeyFrameManager::shouldAnimateFrame() const { @@ -756,26 +756,24 @@ LayoutAnimationKeyFrameManager::pullTransaction( // Execute stopSurface on any ongoing animations if (inflightAnimationsExistInitially) { - std::vector surfaceIdsToStop{}; + better::set surfaceIdsToStop{}; { std::lock_guard lock(surfaceIdsToStopMutex_); surfaceIdsToStop = surfaceIdsToStop_; - surfaceIdsToStop_ = {}; + surfaceIdsToStop_.clear(); } for (auto it = inflightAnimations_.begin(); it != inflightAnimations_.end();) { const auto &animation = *it; - if (std::find( - surfaceIdsToStop.begin(), - surfaceIdsToStop.end(), - animation.surfaceId) != surfaceIdsToStop.end()) { #ifdef LAYOUT_ANIMATION_VERBOSE_LOGGING - LOG(ERROR) - << "LayoutAnimations: stopping animation due to stopSurface on " - << surfaceId; + LOG(ERROR) + << "LayoutAnimations: stopping animation due to stopSurface on " + << surfaceId; #endif + if (surfaceIdsToStop.find(animation.surfaceId) != + surfaceIdsToStop.end()) { it = inflightAnimations_.erase(it); } else { it++; diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h index eaad96b3abb..d8c629e38be 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -243,7 +244,7 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate, std::vector &conflictingAnimations) const; mutable std::mutex surfaceIdsToStopMutex_; - mutable std::vector surfaceIdsToStop_{}; + mutable better::set surfaceIdsToStop_{}; protected: bool hasComponentDescriptorForShadowView(ShadowView const &shadowView) const;