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

@@ -13,16 +13,16 @@
namespace facebook::yoga {
void layoutAbsoluteChild(
const yoga::Node* const containingNode,
const yoga::Node* const node,
yoga::Node* const child,
const float containingBlockWidth,
const float containingBlockHeight,
const SizingMode widthMode,
const Direction direction,
const yoga::Node* containingNode,
const yoga::Node* node,
yoga::Node* child,
float containingBlockWidth,
float containingBlockHeight,
SizingMode widthMode,
Direction direction,
LayoutData& layoutMarkerData,
const uint32_t depth,
const uint32_t generationCount);
uint32_t depth,
uint32_t generationCount);
void layoutAbsoluteDescendants(
yoga::Node* containingNode,

View File

@@ -80,8 +80,8 @@ static void computeFlexBasisForChild(
const float mainAxisSize = isMainAxisRow ? width : height;
const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight;
float childWidth;
float childHeight;
float childWidth = YGUndefined;
float childHeight = YGUndefined;
SizingMode childWidthSizingMode;
SizingMode childHeightSizingMode;
@@ -120,8 +120,6 @@ static void computeFlexBasisForChild(
} else {
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
// basis).
childWidth = YGUndefined;
childHeight = YGUndefined;
childWidthSizingMode = SizingMode::MaxContent;
childHeightSizingMode = SizingMode::MaxContent;
@@ -606,7 +604,7 @@ static float distributeFreeSpaceSecondPass(
-currentLineChild->resolveFlexShrink() * childFlexBasis;
// Is this child able to shrink?
if (flexShrinkScaledFactor != 0) {
float childSize;
float childSize = YGUndefined;
if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) &&
flexLine.layout.totalFlexShrinkScaledFactors == 0) {
@@ -650,7 +648,7 @@ static float distributeFreeSpaceSecondPass(
const float marginCross = currentLineChild->style().computeMarginForAxis(
crossAxis, availableInnerWidth);
float childCrossSize;
float childCrossSize = YGUndefined;
float childMainSize = updatedMainSize + marginMain;
SizingMode childCrossSizingMode;
SizingMode childMainSizingMode = SizingMode::StretchFit;
@@ -1794,13 +1792,13 @@ static void calculateLayoutImpl(
size_t endIndex = 0;
for (size_t i = 0; i < lineCount; i++) {
const size_t startIndex = endIndex;
size_t ii;
size_t ii = startIndex;
// compute the line's height and find the endIndex
float lineHeight = 0;
float maxAscentForCurrentLine = 0;
float maxDescentForCurrentLine = 0;
for (ii = startIndex; ii < childCount; ii++) {
for (; ii < childCount; ii++) {
const auto child = node->getChild(ii);
if (child->style().display() == Display::None) {
continue;
@@ -1837,113 +1835,110 @@ static void calculateLayoutImpl(
endIndex = ii;
currentLead += i != 0 ? crossAxisGap : 0;
if (performLayout) {
for (ii = startIndex; ii < endIndex; ii++) {
const auto child = node->getChild(ii);
if (child->style().display() == Display::None) {
continue;
}
if (child->style().positionType() != PositionType::Absolute) {
switch (resolveChildAlignment(node, child)) {
case Align::FlexStart: {
child->setLayoutPosition(
currentLead +
child->style().computeFlexStartPosition(
crossAxis, direction, availableInnerWidth),
flexStartEdge(crossAxis));
break;
}
case Align::FlexEnd: {
child->setLayoutPosition(
currentLead + lineHeight -
child->style().computeFlexEndMargin(
crossAxis, direction, availableInnerWidth) -
child->getLayout().measuredDimension(
dimension(crossAxis)),
flexStartEdge(crossAxis));
break;
}
case Align::Center: {
float childHeight =
child->getLayout().measuredDimension(dimension(crossAxis));
child->setLayoutPosition(
currentLead + (lineHeight - childHeight) / 2,
flexStartEdge(crossAxis));
break;
}
case Align::Stretch: {
child->setLayoutPosition(
currentLead +
child->style().computeFlexStartMargin(
crossAxis, direction, availableInnerWidth),
flexStartEdge(crossAxis));
// Remeasure child with the line height as it as been only
// measured with the owners height yet.
if (!child->hasDefiniteLength(
dimension(crossAxis), availableInnerCrossDim)) {
const float childWidth = isMainAxisRow
? (child->getLayout().measuredDimension(
Dimension::Width) +
child->style().computeMarginForAxis(
mainAxis, availableInnerWidth))
: leadPerLine + lineHeight;
const float childHeight = !isMainAxisRow
? (child->getLayout().measuredDimension(
Dimension::Height) +
child->style().computeMarginForAxis(
crossAxis, availableInnerWidth))
: leadPerLine + lineHeight;
if (!(yoga::inexactEquals(
childWidth,
child->getLayout().measuredDimension(
Dimension::Width)) &&
yoga::inexactEquals(
childHeight,
child->getLayout().measuredDimension(
Dimension::Height)))) {
calculateLayoutInternal(
child,
childWidth,
childHeight,
direction,
SizingMode::StretchFit,
SizingMode::StretchFit,
availableInnerWidth,
availableInnerHeight,
true,
LayoutPassReason::kMultilineStretch,
layoutMarkerData,
depth,
generationCount);
}
}
break;
}
case Align::Baseline: {
child->setLayoutPosition(
currentLead + maxAscentForCurrentLine -
calculateBaseline(child) +
child->style().computeFlexStartPosition(
FlexDirection::Column,
direction,
availableInnerCrossDim),
PhysicalEdge::Top);
break;
}
case Align::Auto:
case Align::SpaceBetween:
case Align::SpaceAround:
case Align::SpaceEvenly:
break;
for (ii = startIndex; ii < endIndex; ii++) {
const auto child = node->getChild(ii);
if (child->style().display() == Display::None) {
continue;
}
if (child->style().positionType() != PositionType::Absolute) {
switch (resolveChildAlignment(node, child)) {
case Align::FlexStart: {
child->setLayoutPosition(
currentLead +
child->style().computeFlexStartPosition(
crossAxis, direction, availableInnerWidth),
flexStartEdge(crossAxis));
break;
}
case Align::FlexEnd: {
child->setLayoutPosition(
currentLead + lineHeight -
child->style().computeFlexEndMargin(
crossAxis, direction, availableInnerWidth) -
child->getLayout().measuredDimension(
dimension(crossAxis)),
flexStartEdge(crossAxis));
break;
}
case Align::Center: {
float childHeight =
child->getLayout().measuredDimension(dimension(crossAxis));
child->setLayoutPosition(
currentLead + (lineHeight - childHeight) / 2,
flexStartEdge(crossAxis));
break;
}
case Align::Stretch: {
child->setLayoutPosition(
currentLead +
child->style().computeFlexStartMargin(
crossAxis, direction, availableInnerWidth),
flexStartEdge(crossAxis));
// Remeasure child with the line height as it as been only
// measured with the owners height yet.
if (!child->hasDefiniteLength(
dimension(crossAxis), availableInnerCrossDim)) {
const float childWidth = isMainAxisRow
? (child->getLayout().measuredDimension(Dimension::Width) +
child->style().computeMarginForAxis(
mainAxis, availableInnerWidth))
: leadPerLine + lineHeight;
const float childHeight = !isMainAxisRow
? (child->getLayout().measuredDimension(Dimension::Height) +
child->style().computeMarginForAxis(
crossAxis, availableInnerWidth))
: leadPerLine + lineHeight;
if (!(yoga::inexactEquals(
childWidth,
child->getLayout().measuredDimension(
Dimension::Width)) &&
yoga::inexactEquals(
childHeight,
child->getLayout().measuredDimension(
Dimension::Height)))) {
calculateLayoutInternal(
child,
childWidth,
childHeight,
direction,
SizingMode::StretchFit,
SizingMode::StretchFit,
availableInnerWidth,
availableInnerHeight,
true,
LayoutPassReason::kMultilineStretch,
layoutMarkerData,
depth,
generationCount);
}
}
break;
}
case Align::Baseline: {
child->setLayoutPosition(
currentLead + maxAscentForCurrentLine -
calculateBaseline(child) +
child->style().computeFlexStartPosition(
FlexDirection::Column,
direction,
availableInnerCrossDim),
PhysicalEdge::Top);
break;
}
case Align::Auto:
case Align::SpaceBetween:
case Align::SpaceAround:
case Align::SpaceEvenly:
break;
}
}
}
currentLead = currentLead + leadPerLine + lineHeight;
}
}
@@ -2244,7 +2239,7 @@ bool calculateLayoutInternal(
layout->nextCachedMeasurementsIndex = 0;
}
CachedMeasurement* newCacheEntry;
CachedMeasurement* newCacheEntry = nullptr;
if (performLayout) {
// Use the single layout cache entry.
newCacheEntry = &layout->cachedLayout;

View File

@@ -15,24 +15,24 @@
namespace facebook::yoga {
void calculateLayout(
yoga::Node* const node,
const float ownerWidth,
const float ownerHeight,
const Direction ownerDirection);
yoga::Node* node,
float ownerWidth,
float ownerHeight,
Direction ownerDirection);
bool calculateLayoutInternal(
yoga::Node* const node,
const float availableWidth,
const float availableHeight,
const Direction ownerDirection,
const SizingMode widthSizingMode,
const SizingMode heightSizingMode,
const float ownerWidth,
const float ownerHeight,
const bool performLayout,
const LayoutPassReason reason,
yoga::Node* node,
float availableWidth,
float availableHeight,
Direction ownerDirection,
SizingMode widthSizingMode,
SizingMode heightSizingMode,
float ownerWidth,
float ownerHeight,
bool performLayout,
LayoutPassReason reason,
LayoutData& layoutMarkerData,
const uint32_t depth,
const uint32_t generationCount);
uint32_t depth,
uint32_t generationCount);
} // namespace facebook::yoga

View File

@@ -69,7 +69,7 @@ FlexLine calculateFlexLine(
if (sizeConsumedIncludingMinConstraint + flexBasisWithMinAndMaxConstraints +
childMarginMainAxis + childLeadingGapMainAxis >
availableInnerMainDim &&
isNodeFlexWrap && itemsInFlow.size() > 0) {
isNodeFlexWrap && !itemsInFlow.empty()) {
break;
}

View File

@@ -63,7 +63,7 @@ struct FlexLine {
// computedFlexBasis properly computed(To do this use
// computeFlexBasisForChildren function).
FlexLine calculateFlexLine(
yoga::Node* const node,
yoga::Node* node,
Direction ownerDirection,
float mainAxisownerSize,
float availableInnerWidth,

View File

@@ -15,15 +15,15 @@ namespace facebook::yoga {
// Round a point value to the nearest physical pixel based on DPI
// (pointScaleFactor)
float roundValueToPixelGrid(
const double value,
const double pointScaleFactor,
const bool forceCeil,
const bool forceFloor);
double value,
double pointScaleFactor,
bool forceCeil,
bool forceFloor);
// Round the layout results of a node and its subtree to the pixel grid.
void roundLayoutResultsToPixelGrid(
yoga::Node* const node,
const double absoluteLeft,
const double absoluteTop);
yoga::Node* node,
double absoluteLeft,
double absoluteTop);
} // namespace facebook::yoga