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
This commit is contained in:
Samuel Susla
2021-09-08 06:46:52 -07:00
committed by Facebook GitHub Bot
parent 30887403ec
commit cb58c84dc0
2 changed files with 10 additions and 11 deletions
@@ -340,7 +340,7 @@ bool LayoutAnimationKeyFrameManager::shouldOverridePullTransaction() const {
void LayoutAnimationKeyFrameManager::stopSurface(SurfaceId surfaceId) {
std::lock_guard<std::mutex> 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<SurfaceId> surfaceIdsToStop{};
better::set<SurfaceId> surfaceIdsToStop{};
{
std::lock_guard<std::mutex> 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++;
@@ -9,6 +9,7 @@
#include <ReactCommon/RuntimeExecutor.h>
#include <better/optional.h>
#include <better/set.h>
#include <react/renderer/core/EventTarget.h>
#include <react/renderer/core/RawValue.h>
#include <react/renderer/debug/flags.h>
@@ -243,7 +244,7 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
std::vector<AnimationKeyFrame> &conflictingAnimations) const;
mutable std::mutex surfaceIdsToStopMutex_;
mutable std::vector<SurfaceId> surfaceIdsToStop_{};
mutable better::set<SurfaceId> surfaceIdsToStop_{};
protected:
bool hasComponentDescriptorForShadowView(ShadowView const &shadowView) const;