Skip to content

Commit 5019e41

Browse files
Remove double-conversion dependency and also DoubleConversions.cpp and replace it with DebugStringConvertible (#56110)
Summary: **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
1 parent c533369 commit 5019e41

16 files changed

Lines changed: 41 additions & 140 deletions

packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ add_react_common_subdir(react/renderer/css)
9999
add_react_common_subdir(react/renderer/uimanager/consistency)
100100
add_react_common_subdir(react/renderer/dom)
101101
add_react_common_subdir(react/renderer/element)
102-
add_react_common_subdir(react/renderer/graphics)
103102
add_react_common_subdir(react/renderer/debug)
103+
add_react_common_subdir(react/renderer/graphics)
104104
add_react_common_subdir(react/renderer/imagemanager)
105105
add_react_common_subdir(react/renderer/components/view)
106106
add_react_common_subdir(react/renderer/components/switch)

packages/react-native/ReactCommon/react/renderer/debug/DebugStringConvertible.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ std::string toString(const double& value) {
152152
return result;
153153
}
154154

155+
std::string toString(double doubleValue, char suffix) {
156+
auto result = toString(doubleValue);
157+
if (suffix != '\0') {
158+
result += suffix;
159+
}
160+
return result;
161+
}
162+
155163
std::string toString(const void* value) {
156164
if (value == nullptr) {
157165
return "null";

packages/react-native/ReactCommon/react/renderer/debug/DebugStringConvertible.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class DebugStringConvertible {};
8888
* `std::string`
8989
*/
9090
std::string toString(const double &value);
91+
std::string toString(double doubleValue, char suffix);
9192
std::string toString(const void *value);
9293

9394
inline std::string toString(const std::string &value)

packages/react-native/ReactCommon/react/renderer/debug/tests/DebugStringConvertibleTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77

88
#if RN_DEBUG_STRING_CONVERTIBLE
9+
#include <limits>
910
#include <memory>
1011

1112
#include <gtest/gtest.h>
13+
#include <react/renderer/debug/DebugStringConvertible.h>
1214
#include <react/renderer/debug/DebugStringConvertibleItem.h>
1315

1416
using namespace facebook::react;
@@ -83,4 +85,30 @@ TEST(DebugStringConvertibleTest, handleNodeWithComplexProps) {
8385
item->getDebugDescription().c_str(),
8486
"<View=hello x=1(height=100 width=200)/>");
8587
}
88+
89+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffix) {
90+
EXPECT_EQ(toString(3.14, '%'), "3.14%");
91+
EXPECT_EQ(toString(100.0, 'x'), "100x");
92+
}
93+
94+
TEST(DebugStringConvertibleTest, toStringDoubleWithNullSuffix) {
95+
auto result = toString(42.0, '\0');
96+
EXPECT_EQ(result, "42");
97+
}
98+
99+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixZeroValue) {
100+
EXPECT_EQ(toString(0.0, '%'), "0%");
101+
}
102+
103+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixNegativeValue) {
104+
EXPECT_EQ(toString(-2.75, '%'), "-2.75%");
105+
}
106+
107+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixSpecialValues) {
108+
EXPECT_EQ(
109+
toString(std::numeric_limits<double>::infinity(), '%'), "Infinity%");
110+
EXPECT_EQ(
111+
toString(-std::numeric_limits<double>::infinity(), '%'), "-Infinity%");
112+
EXPECT_EQ(toString(std::numeric_limits<double>::quiet_NaN(), 'x'), "NaNx");
113+
}
86114
#endif

packages/react-native/ReactCommon/react/renderer/graphics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ target_link_libraries(react_renderer_graphics
3030
${fbjni}
3131
folly_runtime
3232
react_debug
33+
react_renderer_debug
3334
react_utils
3435
)
3536
target_compile_reactnative_options(react_renderer_graphics PRIVATE)

packages/react-native/ReactCommon/react/renderer/graphics/DoubleConversions.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/react-native/ReactCommon/react/renderer/graphics/DoubleConversions.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/react-native/ReactCommon/react/renderer/graphics/React-graphics.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Pod::Spec.new do |s|
4949
s.dependency "React-jsiexecutor"
5050
s.dependency "React-featureflags"
5151
s.dependency "React-utils"
52+
s.dependency "React-rendererdebug"
5253

5354
depend_on_js_engine(s)
5455
add_rn_third_party_dependencies(s)

packages/react-native/ReactCommon/react/renderer/graphics/ValueUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "ValueUnit.h"
99

10-
#include "DoubleConversions.h"
10+
#include <react/renderer/debug/DebugStringConvertible.h>
1111

1212
namespace facebook::react {
1313

packages/react-native/ReactCommon/react/renderer/graphics/tests/DoubleConversionsTest.cpp

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)