mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Remove double-conversion dependency and also DoubleConversions.cpp and replace it with DebugStringConvertible (#56110)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56110 **Summary** Removes the `double-conversion` dependency from `DoubleConversions.cpp` in the React Native repository. - Removed Dependencies: `double-conversion/double-conversion.h` Updated Code * Modified `DoubleConversions.cpp` to use standard C++ library headers (`cmath` and `cstdio`) instead of `double-conversion`. This change aims to reduce dependencies and simplify the codebase. The removed dependency was previously used for string conversion, which has been replaced with standard C++ library functions. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D96082175 fbshipit-source-id: abfb09d1175eba33e1a1694191f11534b4e7a00e
This commit is contained in:
1 parent
084456ea0a
commit
5b9cefcf90
16 files changed
+60
-139
No files matched your search
@@ -99,8 +99,8 @@ add_react_common_subdir(react/renderer/css)
|
||||
add_react_common_subdir(react/renderer/uimanager/consistency)
|
||||
add_react_common_subdir(react/renderer/dom)
|
||||
add_react_common_subdir(react/renderer/element)
|
||||
add_react_common_subdir(react/renderer/graphics)
|
||||
add_react_common_subdir(react/renderer/debug)
|
||||
add_react_common_subdir(react/renderer/graphics)
|
||||
add_react_common_subdir(react/renderer/imagemanager)
|
||||
add_react_common_subdir(react/renderer/components/view)
|
||||
add_react_common_subdir(react/renderer/components/switch)
|
||||
|
||||
@@ -124,6 +124,8 @@ SharedDebugStringConvertibleList DebugStringConvertible::getDebugProps() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* `toString`-family implementation.
|
||||
*/
|
||||
@@ -152,6 +154,16 @@ std::string toString(const double& value) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string toString(const double doubleValue, char suffix) {
|
||||
auto result = toString(doubleValue);
|
||||
if (suffix != '\0') {
|
||||
result += suffix;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string toString(const void* value) {
|
||||
if (value == nullptr) {
|
||||
return "null";
|
||||
|
||||
@@ -81,13 +81,15 @@ class DebugStringConvertible {};
|
||||
|
||||
#endif
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
/*
|
||||
* Set of particular-format-opinionated functions that convert base types to
|
||||
* `std::string`
|
||||
*/
|
||||
std::string toString(const double &value);
|
||||
std::string toString(double doubleValue, char suffix);
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string toString(const void *value);
|
||||
|
||||
inline std::string toString(const std::string &value)
|
||||
|
||||
+34
-3
@@ -5,14 +5,44 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <react/renderer/debug/DebugStringConvertible.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffix) {
|
||||
EXPECT_EQ(toString(3.14, '%'), "3.14%");
|
||||
EXPECT_EQ(toString(100.0, 'x'), "100x");
|
||||
}
|
||||
|
||||
TEST(DebugStringConvertibleTest, toStringDoubleWithNullSuffix) {
|
||||
auto result = toString(42.0, '\0');
|
||||
EXPECT_EQ(result, "42");
|
||||
}
|
||||
|
||||
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixZeroValue) {
|
||||
EXPECT_EQ(toString(0.0, '%'), "0%");
|
||||
}
|
||||
|
||||
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixNegativeValue) {
|
||||
EXPECT_EQ(toString(-2.75, '%'), "-2.75%");
|
||||
}
|
||||
|
||||
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixSpecialValues) {
|
||||
EXPECT_EQ(
|
||||
toString(std::numeric_limits<double>::infinity(), '%'), "Infinity%");
|
||||
EXPECT_EQ(
|
||||
toString(-std::numeric_limits<double>::infinity(), '%'), "-Infinity%");
|
||||
EXPECT_EQ(toString(std::numeric_limits<double>::quiet_NaN(), 'x'), "NaNx");
|
||||
}
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
#include <memory>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <react/renderer/debug/DebugStringConvertibleItem.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
TEST(DebugStringConvertibleTest, handleSimpleNode) {
|
||||
SharedDebugStringConvertibleList empty;
|
||||
auto item = std::make_shared<DebugStringConvertibleItem>(
|
||||
@@ -83,4 +113,5 @@ TEST(DebugStringConvertibleTest, handleNodeWithComplexProps) {
|
||||
item->getDebugDescription().c_str(),
|
||||
"<View=hello x=1(height=100 width=200)/>");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -30,6 +30,7 @@ target_link_libraries(react_renderer_graphics
|
||||
${fbjni}
|
||||
folly_runtime
|
||||
react_debug
|
||||
react_renderer_debug
|
||||
react_utils
|
||||
)
|
||||
target_compile_reactnative_options(react_renderer_graphics PRIVATE)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "DoubleConversions.h"
|
||||
|
||||
#include <double-conversion/double-conversion.h>
|
||||
#include <array>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
std::string toString(double doubleValue, char suffix) {
|
||||
// Format taken from folly's toString
|
||||
static double_conversion::DoubleToStringConverter conv(
|
||||
0,
|
||||
nullptr,
|
||||
nullptr,
|
||||
'E',
|
||||
-6, // detail::kConvMaxDecimalInShortestLow,
|
||||
21, // detail::kConvMaxDecimalInShortestHigh,
|
||||
6, // max leading padding zeros
|
||||
1); // max trailing padding zeros
|
||||
std::array<char, 256> buffer{};
|
||||
double_conversion::StringBuilder builder(buffer.data(), buffer.size());
|
||||
if (!conv.ToShortest(doubleValue, &builder)) {
|
||||
// Serialize infinite and NaN as 0
|
||||
builder.AddCharacter('0');
|
||||
}
|
||||
if (suffix != '\0') {
|
||||
builder.AddCharacter(suffix);
|
||||
}
|
||||
return builder.Finalize();
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
std::string toString(double doubleValue, char suffix);
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -49,6 +49,7 @@ Pod::Spec.new do |s|
|
||||
s.dependency "React-jsiexecutor"
|
||||
s.dependency "React-featureflags"
|
||||
s.dependency "React-utils"
|
||||
s.dependency "React-rendererdebug"
|
||||
|
||||
depend_on_js_engine(s)
|
||||
add_rn_third_party_dependencies(s)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "ValueUnit.h"
|
||||
|
||||
#include "DoubleConversions.h"
|
||||
#include <react/renderer/debug/DebugStringConvertible.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <react/renderer/graphics/DoubleConversions.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
TEST(DoubleConversionsTest, zeroValue) {
|
||||
EXPECT_EQ(toString(0.0, '\0'), "0");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, negativeZero) {
|
||||
EXPECT_EQ(toString(-0.0, '\0'), "-0");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, positiveIntegers) {
|
||||
EXPECT_EQ(toString(1.0, '\0'), "1");
|
||||
EXPECT_EQ(toString(42.0, '\0'), "42");
|
||||
EXPECT_EQ(toString(1000.0, '\0'), "1000");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, negativeIntegers) {
|
||||
EXPECT_EQ(toString(-1.0, '\0'), "-1");
|
||||
EXPECT_EQ(toString(-42.0, '\0'), "-42");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, fractionalValues) {
|
||||
EXPECT_EQ(toString(3.14, '\0'), "3.14");
|
||||
EXPECT_EQ(toString(0.5, '\0'), "0.5");
|
||||
EXPECT_EQ(toString(-2.75, '\0'), "-2.75");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, verySmallValues) {
|
||||
EXPECT_EQ(toString(0.000001, '\0'), "0.000001");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, veryLargeValues) {
|
||||
EXPECT_EQ(toString(1e20, '\0'), "100000000000000000000");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, scientificNotation) {
|
||||
// Values below 1e-6 should use scientific notation
|
||||
auto result = toString(1e-7, '\0');
|
||||
EXPECT_NE(result.find('E'), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, infinitySerializedAsZero) {
|
||||
EXPECT_EQ(toString(std::numeric_limits<double>::infinity(), '\0'), "0");
|
||||
EXPECT_EQ(toString(-std::numeric_limits<double>::infinity(), '\0'), "0");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, nanSerializedAsZero) {
|
||||
EXPECT_EQ(toString(std::numeric_limits<double>::quiet_NaN(), '\0'), "0");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, suffixAppended) {
|
||||
EXPECT_EQ(toString(3.14, '%'), "3.14%");
|
||||
EXPECT_EQ(toString(100.0, 'x'), "100x");
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, nullSuffixNotAppended) {
|
||||
auto result = toString(42.0, '\0');
|
||||
EXPECT_EQ(result, "42");
|
||||
EXPECT_EQ(result.back(), '2');
|
||||
}
|
||||
|
||||
TEST(DoubleConversionsTest, suffixWithSpecialValues) {
|
||||
EXPECT_EQ(toString(std::numeric_limits<double>::infinity(), '%'), "0%");
|
||||
EXPECT_EQ(toString(std::numeric_limits<double>::quiet_NaN(), 'x'), "0x");
|
||||
}
|
||||
@@ -927,6 +927,7 @@ std::pair<facebook::react::Float, facebook::react::Float> facebook::react::calcu
|
||||
std::string facebook::react::base64Encode(const std::string_view s);
|
||||
std::string facebook::react::componentNameByReactViewName(std::string viewName);
|
||||
std::string facebook::react::generateRandomUuidString();
|
||||
std::string facebook::react::toString(const double& value);
|
||||
std::string facebook::react::toString(const facebook::react::AccessibilityRole& accessibilityRole);
|
||||
std::string facebook::react::toString(const facebook::react::AttributedString::Range& range);
|
||||
std::string facebook::react::toString(const facebook::react::BlendMode& blendMode);
|
||||
|
||||
@@ -927,6 +927,7 @@ std::pair<facebook::react::Float, facebook::react::Float> facebook::react::calcu
|
||||
std::string facebook::react::base64Encode(const std::string_view s);
|
||||
std::string facebook::react::componentNameByReactViewName(std::string viewName);
|
||||
std::string facebook::react::generateRandomUuidString();
|
||||
std::string facebook::react::toString(const double& value);
|
||||
std::string facebook::react::toString(const facebook::react::AccessibilityRole& accessibilityRole);
|
||||
std::string facebook::react::toString(const facebook::react::AttributedString::Range& range);
|
||||
std::string facebook::react::toString(const facebook::react::BlendMode& blendMode);
|
||||
|
||||
@@ -4120,6 +4120,7 @@ std::pair<facebook::react::Float, facebook::react::Float> facebook::react::calcu
|
||||
std::string facebook::react::base64Encode(const std::string_view s);
|
||||
std::string facebook::react::componentNameByReactViewName(std::string viewName);
|
||||
std::string facebook::react::generateRandomUuidString();
|
||||
std::string facebook::react::toString(const double& value);
|
||||
std::string facebook::react::toString(const facebook::react::AccessibilityRole& accessibilityRole);
|
||||
std::string facebook::react::toString(const facebook::react::AttributedString::Range& range);
|
||||
std::string facebook::react::toString(const facebook::react::BlendMode& blendMode);
|
||||
|
||||
@@ -4120,6 +4120,7 @@ std::pair<facebook::react::Float, facebook::react::Float> facebook::react::calcu
|
||||
std::string facebook::react::base64Encode(const std::string_view s);
|
||||
std::string facebook::react::componentNameByReactViewName(std::string viewName);
|
||||
std::string facebook::react::generateRandomUuidString();
|
||||
std::string facebook::react::toString(const double& value);
|
||||
std::string facebook::react::toString(const facebook::react::AccessibilityRole& accessibilityRole);
|
||||
std::string facebook::react::toString(const facebook::react::AttributedString::Range& range);
|
||||
std::string facebook::react::toString(const facebook::react::BlendMode& blendMode);
|
||||
|
||||
@@ -503,6 +503,7 @@ std::pair<Float, Float> facebook::react::calculateAnimationProgress(uint64_t now
|
||||
std::string facebook::react::base64Encode(const std::string_view s);
|
||||
std::string facebook::react::componentNameByReactViewName(std::string viewName);
|
||||
std::string facebook::react::generateRandomUuidString();
|
||||
std::string facebook::react::toString(const double& value);
|
||||
std::string facebook::react::toString(const facebook::react::AccessibilityRole& accessibilityRole);
|
||||
std::string facebook::react::toString(const facebook::react::AttributedString::Range& range);
|
||||
std::string facebook::react::toString(const facebook::react::BlendMode& blendMode);
|
||||
|
||||
@@ -503,6 +503,7 @@ std::pair<Float, Float> facebook::react::calculateAnimationProgress(uint64_t now
|
||||
std::string facebook::react::base64Encode(const std::string_view s);
|
||||
std::string facebook::react::componentNameByReactViewName(std::string viewName);
|
||||
std::string facebook::react::generateRandomUuidString();
|
||||
std::string facebook::react::toString(const double& value);
|
||||
std::string facebook::react::toString(const facebook::react::AccessibilityRole& accessibilityRole);
|
||||
std::string facebook::react::toString(const facebook::react::AttributedString::Range& range);
|
||||
std::string facebook::react::toString(const facebook::react::BlendMode& blendMode);
|
||||
|
||||
Reference in new issue
Block a user