Skip to content

Commit

Permalink
rework on generationCount
Browse files Browse the repository at this point in the history
  • Loading branch information
dattc2 committed Jan 28, 2019
1 parent 3f054bd commit 25caeac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions yoga/YGLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ struct YGLayout {
bool doesLegacyStretchFlagAffectsLayout : 1;
bool hadOverflow : 1;

uint16_t computedFlexBasisGeneration = 0;
uint8_t computedFlexBasisGeneration = 0;
YGFloatOptional computedFlexBasis = {};

// Instead of recomputing the entire layout every single time, we cache some
// information to break early when nothing changed
uint16_t generationCount = 0;
uint8_t generationCount = 0;
YGDirection lastOwnerDirection = (YGDirection) -1;

uint32_t nextCachedMeasurementsIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void YGNode::setLayoutPosition(float position, int index) {
}

void YGNode::setLayoutComputedFlexBasisGeneration(
uint16_t computedFlexBasisGeneration) {
uint8_t computedFlexBasisGeneration) {
layout_.computedFlexBasisGeneration = computedFlexBasisGeneration;
}

Expand Down
2 changes: 1 addition & 1 deletion yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ struct YGNode {
void setLayoutLastOwnerDirection(YGDirection direction);
void setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis);
void setLayoutComputedFlexBasisGeneration(
uint16_t computedFlexBasisGeneration);
uint8_t computedFlexBasisGeneration);
void setLayoutMeasuredDimension(float measuredDimension, int index);
void setLayoutHadOverflow(bool hadOverflow);
void setLayoutDimension(float dimension, int index);
Expand Down
28 changes: 14 additions & 14 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@ bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node) {
return node->getLayout().doesLegacyStretchFlagAffectsLayout;
}

std::atomic<uint8_t> gCurrentGenerationCount(0);

bool YGLayoutNodeInternal(
const YGNodeRef node,
const float availableWidth,
Expand All @@ -1020,7 +1022,7 @@ bool YGLayoutNodeInternal(
const char* reason,
const YGConfigRef config,
const uint32_t depth,
const uint16_t generationCount);
const uint8_t generationCount);

static void YGNodePrintInternal(
const YGNodeRef node,
Expand Down Expand Up @@ -1261,7 +1263,7 @@ static void YGNodeComputeFlexBasisForChild(
const YGDirection direction,
const YGConfigRef config,
const uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
const YGFlexDirection mainAxis =
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis);
Expand Down Expand Up @@ -1454,7 +1456,7 @@ static void YGNodeAbsoluteLayoutChild(
const YGDirection direction,
const YGConfigRef config,
const uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
const YGFlexDirection mainAxis =
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction);
Expand Down Expand Up @@ -1878,7 +1880,7 @@ static float YGNodeComputeFlexBasisForChildren(
const YGConfigRef config,
bool performLayout,
const uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
float totalOuterFlexBasis = 0.0f;
YGNodeRef singleFlexChild = nullptr;
YGVector children = node->getChildren();
Expand Down Expand Up @@ -2058,7 +2060,7 @@ static float YGDistributeFreeSpaceSecondPass(
const bool performLayout,
const YGConfigRef config,
const uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
float childFlexBasis = 0;
float flexShrinkScaledFactor = 0;
float flexGrowFactor = 0;
Expand Down Expand Up @@ -2355,7 +2357,7 @@ static void YGResolveFlexibleLength(
const bool performLayout,
const YGConfigRef config,
const uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
const float originalFreeSpace = collectedFlexItemsValues.remainingFreeSpace;
// First pass: detect the flex items whose min/max constraints trigger
YGDistributeFreeSpaceFirstPass(
Expand Down Expand Up @@ -2679,7 +2681,7 @@ static void YGNodelayoutImpl(
const bool performLayout,
const YGConfigRef config,
const uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
YGAssertWithNode(
node,
YGFloatIsUndefined(availableWidth)
Expand Down Expand Up @@ -3719,7 +3721,7 @@ bool YGLayoutNodeInternal(
const char* reason,
const YGConfigRef config,
uint32_t depth,
const uint16_t generationCount) {
const uint8_t generationCount) {
YGLayout* layout = &node->getLayout();

#if PRINT_CHANGES
Expand Down Expand Up @@ -4045,12 +4047,10 @@ void YGNodeCalculateLayout(
const float ownerWidth,
const float ownerHeight,
const YGDirection ownerDirection) {
uint16_t generationCount = 0;

// Increment the generation count. This will force the recursive routine to
// visit all dirty nodes at least once. Subsequent visits will be skipped if
// the input parameters don't change.
generationCount++;
gCurrentGenerationCount++;
node->resolveDimension();
float width = YGUndefined;
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
Expand Down Expand Up @@ -4109,7 +4109,7 @@ void YGNodeCalculateLayout(
"initial",
node->getConfig(),
0, // tree root
generationCount)) {
gCurrentGenerationCount)) {
node->setPosition(
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);
Expand All @@ -4136,7 +4136,7 @@ void YGNodeCalculateLayout(
originalNode->resolveDimension();
// Recursively mark nodes as dirty
originalNode->markDirtyAndPropogateDownwards();
generationCount++;
gCurrentGenerationCount++;
// Rerun the layout, and calculate the diff
originalNode->setAndPropogateUseLegacyFlag(false);
if (YGLayoutNodeInternal(
Expand All @@ -4152,7 +4152,7 @@ void YGNodeCalculateLayout(
"initial",
originalNode->getConfig(),
0, // tree root
generationCount)) {
gCurrentGenerationCount)) {
originalNode->setPosition(
originalNode->getLayout().direction,
ownerWidth,
Expand Down

0 comments on commit 25caeac

Please sign in to comment.