Skip to content

Commit

Permalink
Use bitfields for enum members of YGStyle
Browse files Browse the repository at this point in the history
Summary:
@public

Puts all enum fields of `YGStyle` into bitfields. This saves 36 bytes (> 3%) per node.

Reviewed By: SidharthGuglani

Differential Revision: D13233686

fbshipit-source-id: 3ef7e0d6913f0254806acb942d9a9f5b78a5af9c
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Dec 6, 2018
1 parent 5a65261 commit 4248fd9
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions yoga/YGStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ constexpr std::array<YGValue, 2> kYGDefaultDimensionValuesUnit = {
struct YGStyle {
using Dimensions = std::array<YGValue, 2>;

YGDirection direction = YGDirectionInherit;
YGFlexDirection flexDirection = YGFlexDirectionColumn;
YGJustify justifyContent = YGJustifyFlexStart;
YGAlign alignContent = YGAlignFlexStart;
YGAlign alignItems = YGAlignStretch;
YGAlign alignSelf = YGAlignAuto;
YGPositionType positionType = YGPositionTypeRelative;
YGWrap flexWrap = YGWrapNoWrap;
YGOverflow overflow = YGOverflowVisible;
YGDisplay display = YGDisplayFlex;
YGDirection direction : 2;
YGFlexDirection flexDirection : 2;
YGJustify justifyContent : 3;
YGAlign alignContent : 3;
YGAlign alignItems : 3;
YGAlign alignSelf : 3;
YGPositionType positionType : 1;
YGWrap flexWrap : 2;
YGOverflow overflow : 2;
YGDisplay display : 1;
YGFloatOptional flex = {};
YGFloatOptional flexGrow = {};
YGFloatOptional flexShrink = {};
Expand All @@ -54,7 +54,17 @@ struct YGStyle {
// Yoga specific properties, not compatible with flexbox specification
YGFloatOptional aspectRatio = {};

YGStyle() = default;
YGStyle()
: direction(YGDirectionInherit),
flexDirection(YGFlexDirectionColumn),
justifyContent(YGJustifyFlexStart),
alignContent(YGAlignFlexStart),
alignItems(YGAlignStretch),
alignSelf(YGAlignAuto),
positionType(YGPositionTypeRelative),
flexWrap(YGWrapNoWrap),
overflow(YGOverflowVisible),
display(YGDisplayFlex) {}
bool operator==(const YGStyle& style);

bool operator!=(YGStyle style) {
Expand Down

0 comments on commit 4248fd9

Please sign in to comment.