Reduce duplicate function calls
Summary: Remove duplicate functions calls. Using instruments I could see a 5% perf increase from this change. Reviewed By: gkassabli Differential Revision: D4068140 fbshipit-source-id: 91261afb73e1c5e23c2cfc84df6ecc5c844a4e78
This commit is contained in:
committed by
Facebook Github Bot
parent
97fef59f96
commit
15f5c4cea5
@@ -645,8 +645,9 @@ static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axi
|
|||||||
return node->style.padding[CSSEdgeStart];
|
return node->style.padding[CSSEdgeStart];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (computedEdgeValue(node->style.padding, leading[axis], 0) >= 0) {
|
const float leadingPadding = computedEdgeValue(node->style.padding, leading[axis], 0);
|
||||||
return computedEdgeValue(node->style.padding, leading[axis], 0);
|
if (leadingPadding >= 0) {
|
||||||
|
return leadingPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -658,8 +659,9 @@ static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection ax
|
|||||||
return node->style.padding[CSSEdgeEnd];
|
return node->style.padding[CSSEdgeEnd];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (computedEdgeValue(node->style.padding, trailing[axis], 0) >= 0) {
|
const float trailingPadding = computedEdgeValue(node->style.padding, trailing[axis], 0);
|
||||||
return computedEdgeValue(node->style.padding, trailing[axis], 0);
|
if (trailingPadding >= 0) {
|
||||||
|
return trailingPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -671,8 +673,9 @@ static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis
|
|||||||
return node->style.border[CSSEdgeStart];
|
return node->style.border[CSSEdgeStart];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (computedEdgeValue(node->style.border, leading[axis], 0) >= 0) {
|
const float leadingBorder = computedEdgeValue(node->style.border, leading[axis], 0);
|
||||||
return computedEdgeValue(node->style.border, leading[axis], 0);
|
if (leadingBorder >= 0) {
|
||||||
|
return leadingBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -684,8 +687,9 @@ static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axi
|
|||||||
return node->style.border[CSSEdgeEnd];
|
return node->style.border[CSSEdgeEnd];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (computedEdgeValue(node->style.border, trailing[axis], 0) >= 0) {
|
const float trailingBorder = computedEdgeValue(node->style.border, trailing[axis], 0);
|
||||||
return computedEdgeValue(node->style.border, trailing[axis], 0);
|
if (trailingBorder >= 0) {
|
||||||
|
return trailingBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -780,24 +784,38 @@ static bool isTrailingPosDefined(const CSSNodeRef node, const CSSFlexDirection a
|
|||||||
}
|
}
|
||||||
|
|
||||||
static float getLeadingPosition(const CSSNodeRef node, const CSSFlexDirection axis) {
|
static float getLeadingPosition(const CSSNodeRef node, const CSSFlexDirection axis) {
|
||||||
if (isRowDirection(axis) &&
|
if (isRowDirection(axis)) {
|
||||||
!CSSValueIsUndefined(computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined))) {
|
const float leadingPosition =
|
||||||
return computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined);
|
computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined);
|
||||||
|
if (!CSSValueIsUndefined(leadingPosition)) {
|
||||||
|
return leadingPosition;
|
||||||
}
|
}
|
||||||
if (!CSSValueIsUndefined(computedEdgeValue(node->style.position, leading[axis], CSSUndefined))) {
|
|
||||||
return computedEdgeValue(node->style.position, leading[axis], CSSUndefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float leadingPosition =
|
||||||
|
computedEdgeValue(node->style.position, leading[axis], CSSUndefined);
|
||||||
|
if (!CSSValueIsUndefined(leadingPosition)) {
|
||||||
|
return leadingPosition;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float getTrailingPosition(const CSSNodeRef node, const CSSFlexDirection axis) {
|
static float getTrailingPosition(const CSSNodeRef node, const CSSFlexDirection axis) {
|
||||||
if (isRowDirection(axis) &&
|
if (isRowDirection(axis)) {
|
||||||
!CSSValueIsUndefined(computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined))) {
|
const float trailingPosition =
|
||||||
return computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined);
|
computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined);
|
||||||
|
if (!CSSValueIsUndefined(trailingPosition)) {
|
||||||
|
return trailingPosition;
|
||||||
}
|
}
|
||||||
if (!CSSValueIsUndefined(computedEdgeValue(node->style.position, trailing[axis], CSSUndefined))) {
|
|
||||||
return computedEdgeValue(node->style.position, trailing[axis], CSSUndefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float trailingPosition =
|
||||||
|
computedEdgeValue(node->style.position, trailing[axis], CSSUndefined);
|
||||||
|
if (!CSSValueIsUndefined(trailingPosition)) {
|
||||||
|
return trailingPosition;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -855,15 +873,17 @@ static float getRelativePosition(const CSSNodeRef node, const CSSFlexDirection a
|
|||||||
static void setPosition(const CSSNodeRef node, const CSSDirection direction) {
|
static void setPosition(const CSSNodeRef node, const CSSDirection direction) {
|
||||||
const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction);
|
const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction);
|
||||||
const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction);
|
const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction);
|
||||||
|
const float relativePositionMain = getRelativePosition(node, mainAxis);
|
||||||
|
const float relativePositionCross = getRelativePosition(node, crossAxis);
|
||||||
|
|
||||||
node->layout.position[leading[mainAxis]] =
|
node->layout.position[leading[mainAxis]] =
|
||||||
getLeadingMargin(node, mainAxis) + getRelativePosition(node, mainAxis);
|
getLeadingMargin(node, mainAxis) + relativePositionMain;
|
||||||
node->layout.position[trailing[mainAxis]] =
|
node->layout.position[trailing[mainAxis]] =
|
||||||
getTrailingMargin(node, mainAxis) + getRelativePosition(node, mainAxis);
|
getTrailingMargin(node, mainAxis) + relativePositionMain;
|
||||||
node->layout.position[leading[crossAxis]] =
|
node->layout.position[leading[crossAxis]] =
|
||||||
getLeadingMargin(node, crossAxis) + getRelativePosition(node, crossAxis);
|
getLeadingMargin(node, crossAxis) + relativePositionCross;
|
||||||
node->layout.position[trailing[crossAxis]] =
|
node->layout.position[trailing[crossAxis]] =
|
||||||
getTrailingMargin(node, crossAxis) + getRelativePosition(node, crossAxis);
|
getTrailingMargin(node, crossAxis) + relativePositionCross;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void computeChildFlexBasis(const CSSNodeRef node,
|
static void computeChildFlexBasis(const CSSNodeRef node,
|
||||||
@@ -881,17 +901,20 @@ static void computeChildFlexBasis(const CSSNodeRef node,
|
|||||||
CSSMeasureMode childWidthMeasureMode;
|
CSSMeasureMode childWidthMeasureMode;
|
||||||
CSSMeasureMode childHeightMeasureMode;
|
CSSMeasureMode childHeightMeasureMode;
|
||||||
|
|
||||||
|
const bool isRowStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionRow);
|
||||||
|
const bool isColumnStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionColumn);
|
||||||
|
|
||||||
if (!CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(child)) &&
|
if (!CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(child)) &&
|
||||||
!CSSValueIsUndefined(isMainAxisRow ? width : height)) {
|
!CSSValueIsUndefined(isMainAxisRow ? width : height)) {
|
||||||
if (CSSValueIsUndefined(child->layout.computedFlexBasis)) {
|
if (CSSValueIsUndefined(child->layout.computedFlexBasis)) {
|
||||||
child->layout.computedFlexBasis =
|
child->layout.computedFlexBasis =
|
||||||
fmaxf(CSSNodeStyleGetFlexBasis(child), getPaddingAndBorderAxis(child, mainAxis));
|
fmaxf(CSSNodeStyleGetFlexBasis(child), getPaddingAndBorderAxis(child, mainAxis));
|
||||||
}
|
}
|
||||||
} else if (isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionRow)) {
|
} else if (isMainAxisRow && isRowStyleDimDefined) {
|
||||||
// The width is definite, so use that as the flex basis.
|
// The width is definite, so use that as the flex basis.
|
||||||
child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionWidth],
|
child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionWidth],
|
||||||
getPaddingAndBorderAxis(child, CSSFlexDirectionRow));
|
getPaddingAndBorderAxis(child, CSSFlexDirectionRow));
|
||||||
} else if (!isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionColumn)) {
|
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||||
// The height is definite, so use that as the flex basis.
|
// The height is definite, so use that as the flex basis.
|
||||||
child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionHeight],
|
child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionHeight],
|
||||||
getPaddingAndBorderAxis(child, CSSFlexDirectionColumn));
|
getPaddingAndBorderAxis(child, CSSFlexDirectionColumn));
|
||||||
@@ -903,12 +926,12 @@ static void computeChildFlexBasis(const CSSNodeRef node,
|
|||||||
childWidthMeasureMode = CSSMeasureModeUndefined;
|
childWidthMeasureMode = CSSMeasureModeUndefined;
|
||||||
childHeightMeasureMode = CSSMeasureModeUndefined;
|
childHeightMeasureMode = CSSMeasureModeUndefined;
|
||||||
|
|
||||||
if (isStyleDimDefined(child, CSSFlexDirectionRow)) {
|
if (isRowStyleDimDefined) {
|
||||||
childWidth =
|
childWidth =
|
||||||
child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow);
|
child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow);
|
||||||
childWidthMeasureMode = CSSMeasureModeExactly;
|
childWidthMeasureMode = CSSMeasureModeExactly;
|
||||||
}
|
}
|
||||||
if (isStyleDimDefined(child, CSSFlexDirectionColumn)) {
|
if (isColumnStyleDimDefined) {
|
||||||
childHeight = child->style.dimensions[CSSDimensionHeight] +
|
childHeight = child->style.dimensions[CSSDimensionHeight] +
|
||||||
getMarginAxis(child, CSSFlexDirectionColumn);
|
getMarginAxis(child, CSSFlexDirectionColumn);
|
||||||
childHeightMeasureMode = CSSMeasureModeExactly;
|
childHeightMeasureMode = CSSMeasureModeExactly;
|
||||||
@@ -935,15 +958,13 @@ static void computeChildFlexBasis(const CSSNodeRef node,
|
|||||||
// If child has no defined size in the cross axis and is set to stretch,
|
// If child has no defined size in the cross axis and is set to stretch,
|
||||||
// set the cross
|
// set the cross
|
||||||
// axis to be measured exactly with the available inner width
|
// axis to be measured exactly with the available inner width
|
||||||
if (!isMainAxisRow && !CSSValueIsUndefined(width) &&
|
if (!isMainAxisRow && !CSSValueIsUndefined(width) && !isRowStyleDimDefined &&
|
||||||
!isStyleDimDefined(child, CSSFlexDirectionRow) && widthMode == CSSMeasureModeExactly &&
|
widthMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) {
|
||||||
getAlignItem(node, child) == CSSAlignStretch) {
|
|
||||||
childWidth = width;
|
childWidth = width;
|
||||||
childWidthMeasureMode = CSSMeasureModeExactly;
|
childWidthMeasureMode = CSSMeasureModeExactly;
|
||||||
}
|
}
|
||||||
if (isMainAxisRow && !CSSValueIsUndefined(height) &&
|
if (isMainAxisRow && !CSSValueIsUndefined(height) && !isColumnStyleDimDefined &&
|
||||||
!isStyleDimDefined(child, CSSFlexDirectionColumn) && heightMode == CSSMeasureModeExactly &&
|
heightMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) {
|
||||||
getAlignItem(node, child) == CSSAlignStretch) {
|
|
||||||
childHeight = height;
|
childHeight = height;
|
||||||
childHeightMeasureMode = CSSMeasureModeExactly;
|
childHeightMeasureMode = CSSMeasureModeExactly;
|
||||||
}
|
}
|
||||||
@@ -1437,7 +1458,8 @@ static void layoutNodeImpl(const CSSNodeRef node,
|
|||||||
// Unlike the grow factor, the shrink factor is scaled relative to the
|
// Unlike the grow factor, the shrink factor is scaled relative to the
|
||||||
// child
|
// child
|
||||||
// dimension.
|
// dimension.
|
||||||
totalFlexShrinkScaledFactors += -CSSNodeStyleGetFlexShrink(child) * child->layout.computedFlexBasis;
|
totalFlexShrinkScaledFactors +=
|
||||||
|
-CSSNodeStyleGetFlexShrink(child) * child->layout.computedFlexBasis;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store a private linked list of children that need to be layed out.
|
// Store a private linked list of children that need to be layed out.
|
||||||
@@ -1520,7 +1542,8 @@ static void layoutNodeImpl(const CSSNodeRef node,
|
|||||||
childFlexBasis = currentRelativeChild->layout.computedFlexBasis;
|
childFlexBasis = currentRelativeChild->layout.computedFlexBasis;
|
||||||
|
|
||||||
if (remainingFreeSpace < 0) {
|
if (remainingFreeSpace < 0) {
|
||||||
flexShrinkScaledFactor = -CSSNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis;
|
flexShrinkScaledFactor =
|
||||||
|
-CSSNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis;
|
||||||
|
|
||||||
// Is this child able to shrink?
|
// Is this child able to shrink?
|
||||||
if (flexShrinkScaledFactor != 0) {
|
if (flexShrinkScaledFactor != 0) {
|
||||||
@@ -1575,7 +1598,8 @@ static void layoutNodeImpl(const CSSNodeRef node,
|
|||||||
float updatedMainSize = childFlexBasis;
|
float updatedMainSize = childFlexBasis;
|
||||||
|
|
||||||
if (remainingFreeSpace < 0) {
|
if (remainingFreeSpace < 0) {
|
||||||
flexShrinkScaledFactor = -CSSNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis;
|
flexShrinkScaledFactor =
|
||||||
|
-CSSNodeStyleGetFlexShrink(currentRelativeChild) * childFlexBasis;
|
||||||
// Is this child able to shrink?
|
// Is this child able to shrink?
|
||||||
if (flexShrinkScaledFactor != 0) {
|
if (flexShrinkScaledFactor != 0) {
|
||||||
float childSize;
|
float childSize;
|
||||||
|
Reference in New Issue
Block a user