Enable Clang Tidy (#1586)

Summary:
X-link: https://github.com/facebook/litho/pull/976

Pull Request resolved: https://github.com/facebook/yoga/pull/1586

X-link: https://github.com/facebook/react-native/pull/43299

Add the React Clang Tidy config to Yoga, run the auto fixes, and make some manual mechanical tweaks.

Notably, the automatic changes to the infra for generating a Yoga tree from JSON capture make it 70% faster.

Before:
{F1463947076}

After:
{F1463946802}

This also cleans up all the no-op shallow const parameters in headers.

{F1463943386}

Not all checks are available in all environments, but that is okay, as Clang Tidy will gracefully skip them.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D54461054

fbshipit-source-id: dbd2d9ce51afd3174d1f2c6d439fa7d08baff46f
This commit is contained in:
Nick Gerleman
2024-03-04 02:28:02 -08:00
committed by Facebook GitHub Bot
parent 47a56db5f6
commit b959c79a2a
43 changed files with 537 additions and 306 deletions

View File

@@ -26,23 +26,23 @@ Node::Node(const yoga::Config* config) : config_{config} {
}
}
Node::Node(Node&& node) {
hasNewLayout_ = node.hasNewLayout_;
isReferenceBaseline_ = node.isReferenceBaseline_;
isDirty_ = node.isDirty_;
alwaysFormsContainingBlock_ = node.alwaysFormsContainingBlock_;
nodeType_ = node.nodeType_;
context_ = node.context_;
measureFunc_ = node.measureFunc_;
baselineFunc_ = node.baselineFunc_;
dirtiedFunc_ = node.dirtiedFunc_;
style_ = node.style_;
layout_ = node.layout_;
lineIndex_ = node.lineIndex_;
owner_ = node.owner_;
children_ = std::move(node.children_);
config_ = node.config_;
resolvedDimensions_ = node.resolvedDimensions_;
Node::Node(Node&& node) noexcept
: hasNewLayout_(node.hasNewLayout_),
isReferenceBaseline_(node.isReferenceBaseline_),
isDirty_(node.isDirty_),
alwaysFormsContainingBlock_(node.alwaysFormsContainingBlock_),
nodeType_(node.nodeType_),
context_(node.context_),
measureFunc_(node.measureFunc_),
baselineFunc_(node.baselineFunc_),
dirtiedFunc_(node.dirtiedFunc_),
style_(std::move(node.style_)),
layout_(node.layout_),
lineIndex_(node.lineIndex_),
owner_(node.owner_),
children_(std::move(node.children_)),
config_(node.config_),
resolvedDimensions_(node.resolvedDimensions_) {
for (auto c : children_) {
c->setOwner(this);
}
@@ -83,7 +83,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
} else {
yoga::assertFatalWithNode(
this,
children_.size() == 0,
children_.empty(),
"Cannot set measure function: Nodes with measure functions cannot have "
"children.");
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
@@ -122,18 +122,17 @@ void Node::setConfig(yoga::Config* config) {
}
void Node::setDirty(bool isDirty) {
if (isDirty == isDirty_) {
if (static_cast<int>(isDirty) == isDirty_) {
return;
}
isDirty_ = isDirty;
if (isDirty && dirtiedFunc_) {
if (isDirty && (dirtiedFunc_ != nullptr)) {
dirtiedFunc_(this);
}
}
bool Node::removeChild(Node* child) {
std::vector<Node*>::iterator p =
std::find(children_.begin(), children_.end(), child);
auto p = std::find(children_.begin(), children_.end(), child);
if (p != children_.end()) {
children_.erase(p);
return true;
@@ -307,7 +306,7 @@ void Node::markDirtyAndPropagate() {
if (!isDirty_) {
setDirty(true);
setLayoutComputedFlexBasis(FloatOptional());
if (owner_) {
if (owner_ != nullptr) {
owner_->markDirtyAndPropagate();
}
}
@@ -351,7 +350,7 @@ bool Node::isNodeFlexible() {
void Node::reset() {
yoga::assertFatalWithNode(
this,
children_.size() == 0,
children_.empty(),
"Cannot reset a node which still has children attached");
yoga::assertFatalWithNode(
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");

View File

@@ -7,8 +7,8 @@
#pragma once
#include <stdio.h>
#include <cstdint>
#include <cstdio>
#include <vector>
#include <yoga/Yoga.h>
@@ -34,7 +34,7 @@ class YG_EXPORT Node : public ::YGNode {
Node();
explicit Node(const Config* config);
Node(Node&&);
Node(Node&& node) noexcept;
// Does not expose true value semantics, as children are not cloned eagerly.
// Should we remove this?
@@ -65,7 +65,11 @@ class YG_EXPORT Node : public ::YGNode {
return measureFunc_ != nullptr;
}
YGSize measure(float, MeasureMode, float, MeasureMode);
YGSize measure(
float width,
MeasureMode widthMode,
float height,
MeasureMode heightMode);
bool hasBaselineFunc() const noexcept {
return baselineFunc_ != nullptr;
@@ -73,9 +77,9 @@ class YG_EXPORT Node : public ::YGNode {
float baseline(float width, float height) const;
float dimensionWithMargin(const FlexDirection axis, const float widthSize);
float dimensionWithMargin(FlexDirection axis, float widthSize);
bool isLayoutDimensionDefined(const FlexDirection axis);
bool isLayoutDimensionDefined(FlexDirection axis);
/**
* Whether the node has a "definite length" along the given axis.
@@ -214,7 +218,7 @@ class YG_EXPORT Node : public ::YGNode {
void setDirty(bool isDirty);
void setLayoutLastOwnerDirection(Direction direction);
void setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis);
void setLayoutComputedFlexBasis(FloatOptional computedFlexBasis);
void setLayoutComputedFlexBasisGeneration(
uint32_t computedFlexBasisGeneration);
void setLayoutMeasuredDimension(float measuredDimension, Dimension dimension);
@@ -226,15 +230,15 @@ class YG_EXPORT Node : public ::YGNode {
void setLayoutPadding(float padding, PhysicalEdge edge);
void setLayoutPosition(float position, PhysicalEdge edge);
void setPosition(
const Direction direction,
const float mainSize,
const float crossSize,
const float ownerWidth);
Direction direction,
float mainSize,
float crossSize,
float ownerWidth);
// Other methods
Style::Length resolveFlexBasisPtr() const;
void resolveDimension();
Direction resolveDirection(const Direction ownerDirection);
Direction resolveDirection(Direction ownerDirection);
void clearChildren();
/// Replaces the occurrences of oldChild with newChild
void replaceChild(Node* oldChild, Node* newChild);
@@ -253,12 +257,12 @@ class YG_EXPORT Node : public ::YGNode {
private:
// Used to allow resetting the node
Node& operator=(Node&&) = default;
Node& operator=(Node&&) noexcept = default;
float relativePosition(
FlexDirection axis,
Direction direction,
const float axisSize) const;
float axisSize) const;
void useWebDefaults() {
style_.setFlexDirection(FlexDirection::Row);