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:
David Aurelio
2018-07-11 04:09:40 -07:00
committed by Facebook Github Bot
parent ede2888326
commit 966f5ece4a

View File

@@ -47,8 +47,18 @@ 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;
}
auto obj = YGNodeJobject(root)->lockLocal();
if (!obj) {
YGLog(
root,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
return;
}
static auto widthField = obj->getClass()->getField<jfloat>("mWidth"); static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
static auto heightField = obj->getClass()->getField<jfloat>("mHeight"); static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
static auto leftField = obj->getClass()->getField<jfloat>("mLeft"); static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
@@ -56,8 +66,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
static auto marginLeftField = static auto marginLeftField =
obj->getClass()->getField<jfloat>("mMarginLeft"); obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginTopField = static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
obj->getClass()->getField<jfloat>("mMarginTop");
static auto marginRightField = static auto marginRightField =
obj->getClass()->getField<jfloat>("mMarginRight"); obj->getClass()->getField<jfloat>("mMarginRight");
static auto marginBottomField = static auto marginBottomField =
@@ -74,8 +83,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
static auto borderLeftField = static auto borderLeftField =
obj->getClass()->getField<jfloat>("mBorderLeft"); obj->getClass()->getField<jfloat>("mBorderLeft");
static auto borderTopField = static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
obj->getClass()->getField<jfloat>("mBorderTop");
static auto borderRightField = static auto borderRightField =
obj->getClass()->getField<jfloat>("mBorderRight"); obj->getClass()->getField<jfloat>("mBorderRight");
static auto borderBottomField = static auto borderBottomField =
@@ -85,8 +93,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
obj->getClass()->getField<jint>("mEdgeSetFlag"); obj->getClass()->getField<jint>("mEdgeSetFlag");
static auto hasNewLayoutField = static auto hasNewLayoutField =
obj->getClass()->getField<jboolean>("mHasNewLayout"); obj->getClass()->getField<jboolean>("mHasNewLayout");
static auto doesLegacyStretchBehaviour = static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
obj->getClass()->getField<jboolean>(
"mDoesLegacyStretchFlagAffectsLayout"); "mDoesLegacyStretchFlagAffectsLayout");
/* Those flags needs be in sync with YogaNode.java */ /* Those flags needs be in sync with YogaNode.java */
@@ -107,8 +114,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if ((hasEdgeSetFlag & MARGIN) == MARGIN) { if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
obj->setFieldValue( obj->setFieldValue(
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft)); marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue( obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue( obj->setFieldValue(
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight)); marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue( obj->setFieldValue(
@@ -129,8 +135,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if ((hasEdgeSetFlag & BORDER) == BORDER) { if ((hasEdgeSetFlag & BORDER) == BORDER) {
obj->setFieldValue( obj->setFieldValue(
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft)); borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue( obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
obj->setFieldValue( obj->setFieldValue(
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight)); borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
obj->setFieldValue( obj->setFieldValue(
@@ -144,13 +149,6 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) { for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i)); YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
} }
} else {
YGLog(
root,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
}
}
} }
static void YGPrint(YGNodeRef node) { static void YGPrint(YGNodeRef node) {