guards instead of nested if
Summary: Replaces two nested if-blocks with guards. This is intended to help with restructuring this function in follow-ups. @public Reviewed By: priteshrnandgaonkar Differential Revision: D8785659 fbshipit-source-id: 7b9d63e9814b83b999397c016ad67ad348bb0f72
This commit is contained in:
committed by
Facebook Github Bot
parent
ede2888326
commit
966f5ece4a
@@ -47,109 +47,107 @@ static void YGTransferLayoutDirection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||||
if (root->getHasNewLayout()) {
|
if (!root->getHasNewLayout()) {
|
||||||
if (auto obj = YGNodeJobject(root)->lockLocal()) {
|
return;
|
||||||
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
}
|
||||||
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
auto obj = YGNodeJobject(root)->lockLocal();
|
||||||
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
if (!obj) {
|
||||||
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
YGLog(
|
||||||
|
root,
|
||||||
|
YGLogLevelError,
|
||||||
|
"Java YGNode was GCed during layout calculation\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static auto marginLeftField =
|
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
||||||
obj->getClass()->getField<jfloat>("mMarginLeft");
|
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
||||||
static auto marginTopField =
|
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
||||||
obj->getClass()->getField<jfloat>("mMarginTop");
|
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
||||||
static auto marginRightField =
|
|
||||||
obj->getClass()->getField<jfloat>("mMarginRight");
|
|
||||||
static auto marginBottomField =
|
|
||||||
obj->getClass()->getField<jfloat>("mMarginBottom");
|
|
||||||
|
|
||||||
static auto paddingLeftField =
|
static auto marginLeftField =
|
||||||
obj->getClass()->getField<jfloat>("mPaddingLeft");
|
obj->getClass()->getField<jfloat>("mMarginLeft");
|
||||||
static auto paddingTopField =
|
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
|
||||||
obj->getClass()->getField<jfloat>("mPaddingTop");
|
static auto marginRightField =
|
||||||
static auto paddingRightField =
|
obj->getClass()->getField<jfloat>("mMarginRight");
|
||||||
obj->getClass()->getField<jfloat>("mPaddingRight");
|
static auto marginBottomField =
|
||||||
static auto paddingBottomField =
|
obj->getClass()->getField<jfloat>("mMarginBottom");
|
||||||
obj->getClass()->getField<jfloat>("mPaddingBottom");
|
|
||||||
|
|
||||||
static auto borderLeftField =
|
static auto paddingLeftField =
|
||||||
obj->getClass()->getField<jfloat>("mBorderLeft");
|
obj->getClass()->getField<jfloat>("mPaddingLeft");
|
||||||
static auto borderTopField =
|
static auto paddingTopField =
|
||||||
obj->getClass()->getField<jfloat>("mBorderTop");
|
obj->getClass()->getField<jfloat>("mPaddingTop");
|
||||||
static auto borderRightField =
|
static auto paddingRightField =
|
||||||
obj->getClass()->getField<jfloat>("mBorderRight");
|
obj->getClass()->getField<jfloat>("mPaddingRight");
|
||||||
static auto borderBottomField =
|
static auto paddingBottomField =
|
||||||
obj->getClass()->getField<jfloat>("mBorderBottom");
|
obj->getClass()->getField<jfloat>("mPaddingBottom");
|
||||||
|
|
||||||
static auto edgeSetFlagField =
|
static auto borderLeftField =
|
||||||
obj->getClass()->getField<jint>("mEdgeSetFlag");
|
obj->getClass()->getField<jfloat>("mBorderLeft");
|
||||||
static auto hasNewLayoutField =
|
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
|
||||||
obj->getClass()->getField<jboolean>("mHasNewLayout");
|
static auto borderRightField =
|
||||||
static auto doesLegacyStretchBehaviour =
|
obj->getClass()->getField<jfloat>("mBorderRight");
|
||||||
obj->getClass()->getField<jboolean>(
|
static auto borderBottomField =
|
||||||
"mDoesLegacyStretchFlagAffectsLayout");
|
obj->getClass()->getField<jfloat>("mBorderBottom");
|
||||||
|
|
||||||
/* Those flags needs be in sync with YogaNode.java */
|
static auto edgeSetFlagField =
|
||||||
const int MARGIN = 1;
|
obj->getClass()->getField<jint>("mEdgeSetFlag");
|
||||||
const int PADDING = 2;
|
static auto hasNewLayoutField =
|
||||||
const int BORDER = 4;
|
obj->getClass()->getField<jboolean>("mHasNewLayout");
|
||||||
|
static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
|
||||||
|
"mDoesLegacyStretchFlagAffectsLayout");
|
||||||
|
|
||||||
int hasEdgeSetFlag = (int)obj->getFieldValue(edgeSetFlagField);
|
/* Those flags needs be in sync with YogaNode.java */
|
||||||
|
const int MARGIN = 1;
|
||||||
|
const int PADDING = 2;
|
||||||
|
const int BORDER = 4;
|
||||||
|
|
||||||
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
int hasEdgeSetFlag = (int)obj->getFieldValue(edgeSetFlagField);
|
||||||
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
|
||||||
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
|
||||||
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
|
||||||
obj->setFieldValue<jboolean>(
|
|
||||||
doesLegacyStretchBehaviour,
|
|
||||||
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
|
||||||
|
|
||||||
if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
|
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
||||||
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
||||||
marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
obj->setFieldValue<jboolean>(
|
||||||
obj->setFieldValue(
|
doesLegacyStretchBehaviour,
|
||||||
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
||||||
obj->setFieldValue(
|
|
||||||
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((hasEdgeSetFlag & PADDING) == PADDING) {
|
if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(
|
||||||
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
||||||
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
obj->setFieldValue(
|
||||||
obj->setFieldValue(
|
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
||||||
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
obj->setFieldValue(
|
||||||
obj->setFieldValue(
|
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
||||||
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((hasEdgeSetFlag & BORDER) == BORDER) {
|
if ((hasEdgeSetFlag & PADDING) == PADDING) {
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(
|
||||||
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(
|
||||||
borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(
|
||||||
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(
|
||||||
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
if ((hasEdgeSetFlag & BORDER) == BORDER) {
|
||||||
YGTransferLayoutDirection(root, obj);
|
obj->setFieldValue(
|
||||||
root->setHasNewLayout(false);
|
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
||||||
|
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
||||||
|
obj->setFieldValue(
|
||||||
|
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
||||||
|
obj->setFieldValue(
|
||||||
|
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
||||||
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
YGTransferLayoutDirection(root, obj);
|
||||||
}
|
root->setHasNewLayout(false);
|
||||||
} else {
|
|
||||||
YGLog(
|
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||||
root,
|
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
||||||
YGLogLevelError,
|
|
||||||
"Java YGNode was GCed during layout calculation\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user