From 080d16cabf9cd354dfd1a4f47e7e97ff2b4347a4 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 2 May 2023 17:08:24 -0700 Subject: [PATCH] Cleanup YGValue.h header (#37179) Summary: X-link: https://github.com/facebook/react-native/pull/37179 Pull Request resolved: https://github.com/facebook/yoga/pull/1273 1. Simplify nan handling a bit 2. Remove string literal operators which seem dead enough to remove. These are public, so anyone could be using them, but it seems like almost nobody is. 1. FB has no usages of `using namespace facebook::yoga::literals` (exposing the literal operators) outside of Yoga tests. 1. There is only [a single usage](https://github.com/XITRIX/UIKit/blob/6dfba905ea83c89e255144f7ed90fde8c33ca81a/SDLTest/UIKit.hpp#L19) on GitHub. Reviewed By: yungsters Differential Revision: D45419970 fbshipit-source-id: 8121303e5ae66596132a848a711802081728f4fb --- tests/YGValueTest.cpp | 26 ---------------------- yoga/YGValue.h | 50 ++++++------------------------------------- 2 files changed, 7 insertions(+), 69 deletions(-) diff --git a/tests/YGValueTest.cpp b/tests/YGValueTest.cpp index 46f84a90..3a64d6ea 100644 --- a/tests/YGValueTest.cpp +++ b/tests/YGValueTest.cpp @@ -21,29 +21,3 @@ TEST(YGValue, supports_equality) { (YGValue{YGUndefined, YGUnitUndefined})); ASSERT_EQ((YGValue{0, YGUnitAuto}), (YGValue{-1, YGUnitAuto})); } - -using namespace facebook::yoga::literals; - -TEST(YGValue, supports_double_point_literals) { - ASSERT_EQ(12.5_pt, (YGValue{12.5, YGUnitPoint})); -} - -TEST(YGValue, supports_double_percent_literals) { - ASSERT_EQ(12.5_percent, (YGValue{12.5, YGUnitPercent})); -} - -TEST(YGValue, supports_integral_point_literals) { - ASSERT_EQ(34_pt, (YGValue{34, YGUnitPoint})); -} - -TEST(YGValue, supports_integral_percent_literals) { - ASSERT_EQ(125_percent, (YGValue{125, YGUnitPercent})); -} - -TEST(YGValue, supports_negative_point_literals) { - ASSERT_EQ(-34.5_pt, (YGValue{-34.5, YGUnitPoint})); -} - -TEST(YGValue, supports_negative_percent_literals) { - ASSERT_EQ(-34.5_percent, (YGValue{-34.5, YGUnitPercent})); -} diff --git a/yoga/YGValue.h b/yoga/YGValue.h index 11beb3ec..a4f89f3b 100644 --- a/yoga/YGValue.h +++ b/yoga/YGValue.h @@ -7,28 +7,11 @@ #pragma once -#include #include "YGEnums.h" #include "YGMacros.h" -#if defined(_MSC_VER) && defined(__clang__) -#define COMPILING_WITH_CLANG_ON_WINDOWS -#endif -#if defined(COMPILING_WITH_CLANG_ON_WINDOWS) -#include -constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); -#else YG_EXTERN_C_BEGIN -// Not defined in MSVC++ -#ifndef NAN -static const uint32_t __nan = 0x7fc00000; -#define NAN (*(const float*) __nan) -#endif - -#define YGUndefined NAN -#endif - typedef struct YGValue { float value; YGUnit unit; @@ -38,13 +21,17 @@ YOGA_EXPORT extern const YGValue YGValueAuto; YOGA_EXPORT extern const YGValue YGValueUndefined; YOGA_EXPORT extern const YGValue YGValueZero; -#if !defined(COMPILING_WITH_CLANG_ON_WINDOWS) YG_EXTERN_C_END -#endif -#undef COMPILING_WITH_CLANG_ON_WINDOWS #ifdef __cplusplus +#include +constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); +#else +#include +#define YGUndefined NAN +#endif +#ifdef __cplusplus inline bool operator==(const YGValue& lhs, const YGValue& rhs) { if (lhs.unit != rhs.unit) { return false; @@ -69,27 +56,4 @@ inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { inline YGValue operator-(const YGValue& value) { return {-value.value, value.unit}; } - -namespace facebook { -namespace yoga { -namespace literals { - -inline YGValue operator"" _pt(long double value) { - return YGValue{static_cast(value), YGUnitPoint}; -} -inline YGValue operator"" _pt(unsigned long long value) { - return operator"" _pt(static_cast(value)); -} - -inline YGValue operator"" _percent(long double value) { - return YGValue{static_cast(value), YGUnitPercent}; -} -inline YGValue operator"" _percent(unsigned long long value) { - return operator"" _percent(static_cast(value)); -} - -} // namespace literals -} // namespace yoga -} // namespace facebook - #endif