From ffce7165576b0313b2ec2ca6fb39b58fff5d0c34 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Mon, 15 Apr 2019 05:20:44 -0700 Subject: [PATCH] Use only 4 edges for margin, padding, border in YGLayout Summary: We were using four edges for margin, padding and border. This diff changes the array size in YGLayout for margin, padding, border to reduce YGNode size and corresponding changes while we are setting values in YGLayout. Reduces the YGNode size by 24 bytes Reviewed By: davidaurelio Differential Revision: D14892666 fbshipit-source-id: 94013d5183ee869901267c4c9941fd94fa05d848 --- yoga/YGLayout.h | 6 +++--- yoga/Yoga.cpp | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/yoga/YGLayout.h b/yoga/YGLayout.h index 4daa28ed..c9c821f8 100644 --- a/yoga/YGLayout.h +++ b/yoga/YGLayout.h @@ -14,9 +14,9 @@ constexpr std::array kYGDefaultDimensionValues = { struct YGLayout { std::array position = {}; std::array dimensions = kYGDefaultDimensionValues; - std::array margin = {}; - std::array border = {}; - std::array padding = {}; + std::array margin = {}; + std::array border = {}; + std::array padding = {}; YGDirection direction : 2; bool didUseLegacyFlag : 1; bool doesLegacyStretchFlagAffectsLayout : 1; diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 431a59a8..e2e1d136 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -665,19 +665,19 @@ struct DimensionProp { edge <= YGEdgeEnd, \ "Cannot get layout properties of multi-edge shorthands"); \ \ - if (edge == YGEdgeLeft) { \ + if (edge == YGEdgeStart) { \ if (node->getLayout().direction == YGDirectionRTL) { \ - return node->getLayout().instanceName[YGEdgeEnd]; \ + return node->getLayout().instanceName[YGEdgeRight]; \ } else { \ - return node->getLayout().instanceName[YGEdgeStart]; \ + return node->getLayout().instanceName[YGEdgeLeft]; \ } \ } \ \ - if (edge == YGEdgeRight) { \ + if (edge == YGEdgeEnd) { \ if (node->getLayout().direction == YGDirectionRTL) { \ - return node->getLayout().instanceName[YGEdgeStart]; \ + return node->getLayout().instanceName[YGEdgeLeft]; \ } else { \ - return node->getLayout().instanceName[YGEdgeEnd]; \ + return node->getLayout().instanceName[YGEdgeRight]; \ } \ } \ \ @@ -2674,12 +2674,13 @@ static void YGNodelayoutImpl( const YGFlexDirection flexColumnDirection = YGResolveFlexDirection(YGFlexDirectionColumn, direction); + const YGEdge startEdge = + direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; + const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; node->setLayoutMargin( - node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), - YGEdgeStart); + node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), startEdge); node->setLayoutMargin( - node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), - YGEdgeEnd); + node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), endEdge); node->setLayoutMargin( node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(), YGEdgeTop); @@ -2687,18 +2688,17 @@ static void YGNodelayoutImpl( node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(), YGEdgeBottom); - node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), YGEdgeStart); - node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), YGEdgeEnd); + node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); + node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); node->setLayoutBorder(node->getLeadingBorder(flexColumnDirection), YGEdgeTop); node->setLayoutBorder( node->getTrailingBorder(flexColumnDirection), YGEdgeBottom); node->setLayoutPadding( node->getLeadingPadding(flexRowDirection, ownerWidth).unwrap(), - YGEdgeStart); + startEdge); node->setLayoutPadding( - node->getTrailingPadding(flexRowDirection, ownerWidth).unwrap(), - YGEdgeEnd); + node->getTrailingPadding(flexRowDirection, ownerWidth).unwrap(), endEdge); node->setLayoutPadding( node->getLeadingPadding(flexColumnDirection, ownerWidth).unwrap(), YGEdgeTop);