Fix unnecessary measure calls

Summary:
Fix #334
Closes https://github.com/facebook/yoga/pull/347

Reviewed By: dshahidehpour

Differential Revision: D4455438

Pulled By: emilsjolander

fbshipit-source-id: 013c89e71757d9048708ec85cbb6af9f33ac1ea6
This commit is contained in:
Lukas Wöhrl
2017-01-24 18:57:07 -08:00
committed by Facebook Github Bot
parent a2a84532ff
commit e4b50f2a8d
2 changed files with 43 additions and 2 deletions

View File

@@ -39,6 +39,22 @@ static YGSize _measureMin(YGNodeRef node,
};
}
static YGSize _measure_84_49(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
int *measureCount = (int*) YGNodeGetContext(node);
if (measureCount) {
(*measureCount)++;
}
return YGSize {
.width = 84.f,
.height = 49.f,
};
}
TEST(YogaTest, measure_once_single_flexible_child) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
@@ -131,3 +147,28 @@ TEST(YogaTest, remeasure_with_atmost_computed_width_undefined_height) {
YGNodeFreeRecursive(root);
}
TEST(YogaTest, remeasure_with_already_measured_value_smaller_but_still_float_equal) {
int measureCount = 0;
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 288.f);
YGNodeStyleSetHeight(root, 288.f);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88f);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNew();
YGNodeSetContext(root_child0_child0, &measureCount);
YGNodeSetMeasureFunc(root_child0_child0, _measure_84_49);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
ASSERT_EQ(1, measureCount);
}

View File

@@ -2785,7 +2785,7 @@ static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits(YGMeasureMode s
YGMeasureMode lastSizeMode,
float lastComputedSize) {
return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined &&
size >= lastComputedSize;
(size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize));
}
static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode,
@@ -2794,7 +2794,7 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureM
float lastSize,
float lastComputedSize) {
return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost &&
lastSize > size && lastComputedSize <= size;
lastSize > size && (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize));
}
bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,