From e9bb1efb033b09f78baed881ffe900a086af3113 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 16 Apr 2019 07:09:36 -0700 Subject: [PATCH] Code formatting: allow short inline methods on one line Summary: @public This allows short methods defined in class declarations to occupy a single line. The change makes class declarations more readable. Reviewed By: SidharthGuglani Differential Revision: D14950012 fbshipit-source-id: 1321949475184181c6cceb86613f730e430763e2 --- .clang-format | 2 +- java/jni/YGJNI.cpp | 8 +-- tests/YGConfigTest.cpp | 8 +-- yoga/CompactValue.h | 8 +-- yoga/YGConfig.h | 4 +- yoga/YGFloatOptional.h | 24 +++------ yoga/YGLayout.h | 4 +- yoga/YGMarker.h | 8 +-- yoga/YGNode.h | 112 +++++++++++------------------------------ yoga/Yoga-internal.h | 8 +-- 10 files changed, 47 insertions(+), 139 deletions(-) diff --git a/.clang-format b/.clang-format index 52a48cf2..7bb07207 100644 --- a/.clang-format +++ b/.clang-format @@ -9,7 +9,7 @@ AlignTrailingComments: false AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Empty +AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: true AlwaysBreakAfterReturnType: None diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index b8725c7e..066f832f 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -135,18 +135,14 @@ public: node->setContext(context.asVoidPtr); } - bool has(Edge edge) { - return (edges_ & edge) == edge; - } + bool has(Edge edge) { return (edges_ & edge) == edge; } YGNodeEdges& add(Edge edge) { edges_ |= edge; return *this; } - int get() { - return edges_; - } + int get() { return edges_; } }; struct YogaValue { diff --git a/tests/YGConfigTest.cpp b/tests/YGConfigTest.cpp index 9aa33e00..d43cb29f 100644 --- a/tests/YGConfigTest.cpp +++ b/tests/YGConfigTest.cpp @@ -20,12 +20,8 @@ struct ConfigCloningTest : public ::testing::Test { void TearDown() override; static YGNode clonedNode; - static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { - return &clonedNode; - } - static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { - return nullptr; - } + static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { return &clonedNode; } + static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; } }; TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) { diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index 3cc36a48..20451779 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -134,9 +134,7 @@ public: payload_.repr != ZERO_BITS_PERCENT && std::isnan(payload_.value)); } - bool isAuto() const noexcept { - return payload_.repr == AUTO_BITS; - } + bool isAuto() const noexcept { return payload_.repr == AUTO_BITS; } private: union Payload { @@ -160,9 +158,7 @@ private: Payload payload_; - VISIBLE_FOR_TESTING uint32_t repr() { - return payload_.repr; - } + VISIBLE_FOR_TESTING uint32_t repr() { return payload_.repr; } }; template <> diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h index e0f29c5f..311c1597 100644 --- a/yoga/YGConfig.h +++ b/yoga/YGConfig.h @@ -56,9 +56,7 @@ public: logger_.withContext = logger; loggerUsesContext_ = true; } - void setLogger(std::nullptr_t) { - setLogger(YGLogger{nullptr}); - } + void setLogger(std::nullptr_t) { setLogger(YGLogger{nullptr}); } YGNodeRef cloneNode( YGNodeRef node, diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index 02d4c856..80a851a0 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -19,23 +19,15 @@ public: constexpr YGFloatOptional() = default; // returns the wrapped value, or a value x with YGIsUndefined(x) == true - constexpr float unwrap() const { - return value_; - } + constexpr float unwrap() const { return value_; } - bool isUndefined() const { - return std::isnan(value_); - } + bool isUndefined() const { return std::isnan(value_); } YGFloatOptional operator+(YGFloatOptional op) const { return YGFloatOptional{value_ + op.value_}; } - bool operator>(YGFloatOptional op) const { - return value_ > op.value_; - } - bool operator<(YGFloatOptional op) const { - return value_ < op.value_; - } + bool operator>(YGFloatOptional op) const { return value_ > op.value_; } + bool operator<(YGFloatOptional op) const { return value_ < op.value_; } bool operator>=(YGFloatOptional op) const { return *this > op || *this == op; } @@ -45,14 +37,10 @@ public: bool operator==(YGFloatOptional op) const { return value_ == op.value_ || (isUndefined() && op.isUndefined()); } - bool operator!=(YGFloatOptional op) const { - return !(*this == op); - } + bool operator!=(YGFloatOptional op) const { return !(*this == op); } bool operator==(float val) const { return value_ == val || (isUndefined() && yoga::isUndefined(val)); } - bool operator!=(float val) const { - return !(*this == val); - } + bool operator!=(float val) const { return !(*this == val); } }; diff --git a/yoga/YGLayout.h b/yoga/YGLayout.h index c9c821f8..0e559d74 100644 --- a/yoga/YGLayout.h +++ b/yoga/YGLayout.h @@ -44,7 +44,5 @@ struct YGLayout { hadOverflow(false) {} bool operator==(YGLayout layout) const; - bool operator!=(YGLayout layout) const { - return !(*this == layout); - } + bool operator!=(YGLayout layout) const { return !(*this == layout); } }; diff --git a/yoga/YGMarker.h b/yoga/YGMarker.h index 25362ff5..89b03684 100644 --- a/yoga/YGMarker.h +++ b/yoga/YGMarker.h @@ -62,16 +62,12 @@ struct MarkerData; template <> struct MarkerData { using type = YGMarkerLayoutData; - static type*& get(YGMarkerData& d) { - return d.layout; - } + static type*& get(YGMarkerData& d) { return d.layout; } }; struct NoMarkerData { using type = YGMarkerNoData; - static type*& get(YGMarkerData& d) { - return d.noData; - } + static type*& get(YGMarkerData& d) { return d.noData; } }; template <> diff --git a/yoga/YGNode.h b/yoga/YGNode.h index b5ff98a5..086e3ca0 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -85,23 +85,15 @@ public: YGNode& operator=(const YGNode&) = delete; // Getters - void* getContext() const { - return context_; - } + void* getContext() const { return context_; } void print(void*); - bool getHasNewLayout() const { - return hasNewLayout_; - } + bool getHasNewLayout() const { return hasNewLayout_; } - YGNodeType getNodeType() const { - return nodeType_; - } + YGNodeType getNodeType() const { return nodeType_; } - bool hasMeasureFunc() const noexcept { - return measure_.noContext != nullptr; - } + bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; } YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*); @@ -111,52 +103,32 @@ public: float baseline(float width, float height, void* layoutContext); - YGDirtiedFunc getDirtied() const { - return dirtied_; - } + YGDirtiedFunc getDirtied() const { return dirtied_; } // For Performance reasons passing as reference. - YGStyle& getStyle() { - return style_; - } + YGStyle& getStyle() { return style_; } - const YGStyle& getStyle() const { - return style_; - } + const YGStyle& getStyle() const { return style_; } // For Performance reasons passing as reference. - YGLayout& getLayout() { - return layout_; - } + YGLayout& getLayout() { return layout_; } - const YGLayout& getLayout() const { - return layout_; - } + const YGLayout& getLayout() const { return layout_; } - uint32_t getLineIndex() const { - return lineIndex_; - } + uint32_t getLineIndex() const { return lineIndex_; } - bool isReferenceBaseline() { - return isReferenceBaseline_; - } + bool isReferenceBaseline() { return isReferenceBaseline_; } // returns the YGNodeRef that owns this YGNode. An owner is used to identify // the YogaTree that a YGNode belongs to. This method will return the parent // of the YGNode when a YGNode only belongs to one YogaTree or nullptr when // the YGNode is shared between two or more YogaTrees. - YGNodeRef getOwner() const { - return owner_; - } + YGNodeRef getOwner() const { return owner_; } // Deprecated, use getOwner() instead. - YGNodeRef getParent() const { - return getOwner(); - } + YGNodeRef getParent() const { return getOwner(); } - const YGVector& getChildren() const { - return children_; - } + const YGVector& getChildren() const { return children_; } // Applies a callback to all children, after cloning them if they are not // owned. @@ -174,17 +146,11 @@ public: } } - YGNodeRef getChild(uint32_t index) const { - return children_.at(index); - } + YGNodeRef getChild(uint32_t index) const { return children_.at(index); } - YGConfigRef getConfig() const { - return config_; - } + YGConfigRef getConfig() const { return config_; } - bool isDirty() const { - return isDirty_; - } + bool isDirty() const { return isDirty_; } std::array getResolvedDimensions() const { return resolvedDimensions_; @@ -228,9 +194,7 @@ public: const float widthSize) const; // Setters - void setContext(void* context) { - context_ = context; - } + void setContext(void* context) { context_ = context; } void setPrintFunc(YGPrintFunc printFunc) { print_.noContext = printFunc; @@ -240,17 +204,11 @@ public: print_.withContext = printFunc; printUsesContext_ = true; } - void setPrintFunc(std::nullptr_t) { - setPrintFunc(YGPrintFunc{nullptr}); - } + void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); } - void setHasNewLayout(bool hasNewLayout) { - hasNewLayout_ = hasNewLayout; - } + void setHasNewLayout(bool hasNewLayout) { hasNewLayout_ = hasNewLayout; } - void setNodeType(YGNodeType nodeType) { - nodeType_ = nodeType; - } + void setNodeType(YGNodeType nodeType) { nodeType_ = nodeType; } void setStyleFlexDirection(YGFlexDirection direction) { style_.flexDirection = direction; @@ -278,39 +236,25 @@ public: return setBaselineFunc(YGBaselineFunc{nullptr}); } - void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { - dirtied_ = dirtiedFunc; - } + void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; } - void setStyle(const YGStyle& style) { - style_ = style; - } + void setStyle(const YGStyle& style) { style_ = style; } - void setLayout(const YGLayout& layout) { - layout_ = layout; - } + void setLayout(const YGLayout& layout) { layout_ = layout; } - void setLineIndex(uint32_t lineIndex) { - lineIndex_ = lineIndex; - } + void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; } void setIsReferenceBaseline(bool isReferenceBaseline) { isReferenceBaseline_ = isReferenceBaseline; } - void setOwner(YGNodeRef owner) { - owner_ = owner; - } + void setOwner(YGNodeRef owner) { owner_ = owner; } - void setChildren(const YGVector& children) { - children_ = children; - } + void setChildren(const YGVector& children) { children_ = children; } // TODO: rvalue override for setChildren - void setConfig(YGConfigRef config) { - config_ = config; - } + void setConfig(YGConfigRef config) { config_ = config; } void setDirty(bool isDirty); void setLayoutLastOwnerDirection(YGDirection direction); diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index be815921..a5cf3037 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -112,12 +112,8 @@ public: values_.fill(defaultValue); } - const CompactValue& operator[](size_t i) const noexcept { - return values_[i]; - } - CompactValue& operator[](size_t i) noexcept { - return values_[i]; - } + const CompactValue& operator[](size_t i) const noexcept { return values_[i]; } + CompactValue& operator[](size_t i) noexcept { return values_[i]; } template YGValue get() const noexcept {