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
This commit is contained in:
Samuel Susla
2020-05-14 11:58:58 -07:00
committed by Facebook GitHub Bot
parent 5c60247981
commit a7bbc858c5
14 changed files with 23 additions and 25 deletions
@@ -519,7 +519,7 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
{
auto const &accessibilityActions = _props->accessibilityActions;
if (accessibilityActions.size() == 0) {
if (accessibilityActions.empty()) {
return nil;
}
@@ -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];
}
+1 -1
View File
@@ -274,7 +274,7 @@ static void RNPerformMountInstructions(
auto surfaceId = transaction->getSurfaceId();
auto &mutations = transaction->getMutations();
if (mutations.size() == 0) {
if (mutations.empty()) {
return;
}
+1 -1
View File
@@ -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<ActiveTouch> activeTouches;
activeTouches.reserve(_activeTouches.size());
@@ -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,
};
@@ -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;
}
@@ -96,7 +96,7 @@ void EventQueue::flushStateUpdates() const {
{
std::lock_guard<std::mutex> lock(queueMutex_);
if (stateUpdateQueue_.size() == 0) {
if (stateUpdateQueue_.empty()) {
return;
}
@@ -121,7 +121,7 @@ LayoutMetrics LayoutableShadowNode::getRelativeLayoutMetrics(
auto ancestors = shadowNode.getFamily().getAncestors(ancestorShadowNode);
if (ancestors.size() == 0) {
if (ancestors.empty()) {
return EmptyLayoutMetrics;
}
@@ -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};
}
@@ -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;
}
+2 -2
View File
@@ -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;
}
@@ -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> &&shadowTree) const {
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -153,7 +153,7 @@ ShadowNode::Shared UIManager::getNewestCloneOfShadowNode(
auto ancestors = shadowNode.getFamily().getAncestors(*ancestorShadowNode);
if (ancestors.size() == 0) {
if (ancestors.empty()) {
return nullptr;
}