From a7bbc858c5ec32c526abb8a58c6f0df7fbce4049 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Thu, 14 May 2020 11:55:48 -0700 Subject: [PATCH] Use vector.empty() to check for emptyness Summary: Changelog: [Internal] Using `empty()` vs `size() == 0` or `size() > 0`. It is a more semantic way to check whether container is empty or not. Reviewed By: JoshuaGross Differential Revision: D21573183 fbshipit-source-id: b83283f687432a037941852114717a0f014e28db --- .../ComponentViews/View/RCTViewComponentView.mm | 2 +- React/Fabric/Mounting/RCTComponentViewRegistry.mm | 2 +- React/Fabric/Mounting/RCTMountingManager.mm | 2 +- React/Fabric/RCTSurfaceTouchHandler.mm | 2 +- .../fabric/components/image/ImageShadowNode.cpp | 2 +- .../components/view/yoga/YogaLayoutableShadowNode.cpp | 6 +++--- ReactCommon/fabric/core/events/EventQueue.cpp | 2 +- .../fabric/core/layout/LayoutableShadowNode.cpp | 2 +- ReactCommon/fabric/core/shadownode/ShadowNode.cpp | 2 +- ReactCommon/fabric/mounting/Differentiator.cpp | 11 +++++------ ReactCommon/fabric/mounting/ShadowTree.cpp | 4 ++-- ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp | 3 +-- ReactCommon/fabric/scheduler/Scheduler.cpp | 6 +++--- ReactCommon/fabric/uimanager/UIManager.cpp | 2 +- 14 files changed, 23 insertions(+), 25 deletions(-) diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index b1f12511537..f252344fe62 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -519,7 +519,7 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view) { auto const &accessibilityActions = _props->accessibilityActions; - if (accessibilityActions.size() == 0) { + if (accessibilityActions.empty()) { return nil; } diff --git a/React/Fabric/Mounting/RCTComponentViewRegistry.mm b/React/Fabric/Mounting/RCTComponentViewRegistry.mm index 23d08cef831..b0dbe553b03 100644 --- a/React/Fabric/Mounting/RCTComponentViewRegistry.mm +++ b/React/Fabric/Mounting/RCTComponentViewRegistry.mm @@ -189,7 +189,7 @@ const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024; RCTAssertMainQueue(); auto &recycledViews = _recyclePool[componentHandle]; - if (recycledViews.size() == 0) { + if (recycledViews.empty()) { return [self.componentViewFactory createComponentViewWithComponentHandle:componentHandle]; } diff --git a/React/Fabric/Mounting/RCTMountingManager.mm b/React/Fabric/Mounting/RCTMountingManager.mm index f0c690cd6df..a64b1dd79dd 100644 --- a/React/Fabric/Mounting/RCTMountingManager.mm +++ b/React/Fabric/Mounting/RCTMountingManager.mm @@ -274,7 +274,7 @@ static void RNPerformMountInstructions( auto surfaceId = transaction->getSurfaceId(); auto &mutations = transaction->getMutations(); - if (mutations.size() == 0) { + if (mutations.empty()) { return; } diff --git a/React/Fabric/RCTSurfaceTouchHandler.mm b/React/Fabric/RCTSurfaceTouchHandler.mm index e2de89c668a..63c3699565a 100644 --- a/React/Fabric/RCTSurfaceTouchHandler.mm +++ b/React/Fabric/RCTSurfaceTouchHandler.mm @@ -362,7 +362,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)act { [super reset]; - if (_activeTouches.size() != 0) { + if (!_activeTouches.empty()) { std::vector activeTouches; activeTouches.reserve(_activeTouches.size()); diff --git a/ReactCommon/fabric/components/image/ImageShadowNode.cpp b/ReactCommon/fabric/components/image/ImageShadowNode.cpp index 030d6d8abba..4a00f2c1bf2 100644 --- a/ReactCommon/fabric/components/image/ImageShadowNode.cpp +++ b/ReactCommon/fabric/components/image/ImageShadowNode.cpp @@ -45,7 +45,7 @@ void ImageShadowNode::updateStateIfNeeded() { ImageSource ImageShadowNode::getImageSource() const { auto sources = getConcreteProps().sources; - if (sources.size() == 0) { + if (sources.empty()) { return { /* .type = */ ImageSource::Type::Invalid, }; diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index 04c48fda480..9e15d72e045 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -597,7 +597,7 @@ void YogaLayoutableShadowNode::ensureYogaChildrenOwnersConsistency() const { // The owner might be not equal to the `yogaNode_` though. auto &yogaChildren = yogaNode_.getChildren(); - if (yogaChildren.size() > 0) { + if (!yogaChildren.empty()) { auto owner = yogaChildren.at(0)->getOwner(); for (auto const &child : yogaChildren) { assert(child->getOwner() == owner); @@ -617,7 +617,7 @@ void YogaLayoutableShadowNode::ensureYogaChildrenLookFine() const { for (auto const &yogaChild : yogaChildren) { assert(yogaChild->getContext()); assert(yogaChild->getChildren().size() < 16384); - if (yogaChild->getChildren().size() > 0) { + if (!yogaChild->getChildren().empty()) { assert(!yogaChild->hasMeasureFunc()); } } @@ -635,7 +635,7 @@ void YogaLayoutableShadowNode::ensureYogaChildrenAlighment() const { auto &children = getChildren(); if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) { - assert(yogaChildren.size() == 0); + assert(yogaChildren.empty()); return; } diff --git a/ReactCommon/fabric/core/events/EventQueue.cpp b/ReactCommon/fabric/core/events/EventQueue.cpp index 1d1aa9e6ea0..2861d7a14f0 100644 --- a/ReactCommon/fabric/core/events/EventQueue.cpp +++ b/ReactCommon/fabric/core/events/EventQueue.cpp @@ -96,7 +96,7 @@ void EventQueue::flushStateUpdates() const { { std::lock_guard lock(queueMutex_); - if (stateUpdateQueue_.size() == 0) { + if (stateUpdateQueue_.empty()) { return; } diff --git a/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp b/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp index 4ae44ed720e..ec67fbb6e6e 100644 --- a/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp +++ b/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp @@ -121,7 +121,7 @@ LayoutMetrics LayoutableShadowNode::getRelativeLayoutMetrics( auto ancestors = shadowNode.getFamily().getAncestors(ancestorShadowNode); - if (ancestors.size() == 0) { + if (ancestors.empty()) { return EmptyLayoutMetrics; } diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index f54fedcf22b..9f3618ddf46 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -254,7 +254,7 @@ ShadowNode::Unshared ShadowNode::cloneTree( callback) const { auto ancestors = shadowNodeFamily.getAncestors(*this); - if (ancestors.size() == 0) { + if (ancestors.empty()) { return ShadowNode::Unshared{nullptr}; } diff --git a/ReactCommon/fabric/mounting/Differentiator.cpp b/ReactCommon/fabric/mounting/Differentiator.cpp index fd621ecfb44..0e93586411a 100644 --- a/ReactCommon/fabric/mounting/Differentiator.cpp +++ b/ReactCommon/fabric/mounting/Differentiator.cpp @@ -65,7 +65,7 @@ class TinyMap final { inline Iterator end() { // `back()` asserts on the vector being non-empty - if (vector_.size() == 0 || numErased_ == vector_.size()) { + if (vector_.empty() || numErased_ == vector_.size()) { return nullptr; } @@ -112,7 +112,7 @@ class TinyMap final { */ inline Iterator begin_() { // `front()` asserts on the vector being non-empty - if (vector_.size() == 0 || vector_.size() == numErased_) { + if (vector_.empty() || vector_.size() == numErased_) { return nullptr; } @@ -125,9 +125,8 @@ class TinyMap final { * vector. */ inline void cleanVector(bool forceClean = false) { - if ((numErased_ < (vector_.size() / 2) && !forceClean) || - vector_.size() == 0 || numErased_ == 0 || - numErased_ == erasedAtFront_) { + if ((numErased_ < (vector_.size() / 2) && !forceClean) || vector_.empty() || + numErased_ == 0 || numErased_ == erasedAtFront_) { return; } @@ -259,7 +258,7 @@ static void calculateShadowViewMutations( ShadowView const &parentShadowView, ShadowViewNodePair::List &&oldChildPairs, ShadowViewNodePair::List &&newChildPairs) { - if (oldChildPairs.size() == 0 && newChildPairs.size() == 0) { + if (oldChildPairs.empty() && newChildPairs.empty()) { return; } diff --git a/ReactCommon/fabric/mounting/ShadowTree.cpp b/ReactCommon/fabric/mounting/ShadowTree.cpp index 654d26fed05..a6e4c2c58ec 100644 --- a/ReactCommon/fabric/mounting/ShadowTree.cpp +++ b/ReactCommon/fabric/mounting/ShadowTree.cpp @@ -41,7 +41,7 @@ static ShadowNode::Unshared progressState(ShadowNode const &shadowNode) { } auto newChildren = ShadowNode::ListOfShared{}; - if (shadowNode.getChildren().size() > 0) { + if (!shadowNode.getChildren().empty()) { auto index = size_t{0}; for (auto const &childNode : shadowNode.getChildren()) { auto newChildNode = progressState(*childNode); @@ -170,7 +170,7 @@ static void updateMountedFlag( return; } - if (oldChildren.size() == 0 && newChildren.size() == 0) { + if (oldChildren.empty() && newChildren.empty()) { // Both lists are empty, nothing to do. return; } diff --git a/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp b/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp index f2792af365b..1564bbee14b 100644 --- a/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp +++ b/ReactCommon/fabric/mounting/ShadowTreeRegistry.cpp @@ -12,8 +12,7 @@ namespace react { ShadowTreeRegistry::~ShadowTreeRegistry() { assert( - registry_.size() == 0 && - "Deallocation of non-empty `ShadowTreeRegistry`."); + registry_.empty() && "Deallocation of non-empty `ShadowTreeRegistry`."); } void ShadowTreeRegistry::add(std::unique_ptr &&shadowTree) const { diff --git a/ReactCommon/fabric/scheduler/Scheduler.cpp b/ReactCommon/fabric/scheduler/Scheduler.cpp index cc15c23efc4..cc67b567091 100644 --- a/ReactCommon/fabric/scheduler/Scheduler.cpp +++ b/ReactCommon/fabric/scheduler/Scheduler.cpp @@ -118,10 +118,10 @@ Scheduler::~Scheduler() { }); assert( - surfaceIds.size() == 0 && + surfaceIds.empty() && "Scheduler was destroyed with outstanding Surfaces."); - if (surfaceIds.size() == 0) { + if (surfaceIds.empty()) { return; } @@ -177,7 +177,7 @@ void Scheduler::renderTemplateToSurface( const std::string &uiTemplate) { SystraceSection s("Scheduler::renderTemplateToSurface"); try { - if (uiTemplate.size() == 0) { + if (uiTemplate.empty()) { return; } NativeModuleRegistry nMR; diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index a4bc38f25d9..3de1d006fde 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -153,7 +153,7 @@ ShadowNode::Shared UIManager::getNewestCloneOfShadowNode( auto ancestors = shadowNode.getFamily().getAncestors(*ancestorShadowNode); - if (ancestors.size() == 0) { + if (ancestors.empty()) { return nullptr; }