Skip to content

Commit 4a3f99e

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Remove double-conversion dependency and also DoubleConversions.cpp and replace it with DebugStringConvertible (#56110)
Summary: Pull Request resolved: #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
1 parent b111c0e commit 4a3f99e

16 files changed

Lines changed: 60 additions & 139 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ SharedDebugStringConvertibleList DebugStringConvertible::getDebugProps() const {
124124
return {};
125125
}
126126

127+
#endif
128+
127129
/*
128130
* `toString`-family implementation.
129131
*/
@@ -152,6 +154,16 @@ std::string toString(const double& value) {
152154
return result;
153155
}
154156

157+
std::string toString(const double doubleValue, char suffix) {
158+
auto result = toString(doubleValue);
159+
if (suffix != '\0') {
160+
result += suffix;
161+
}
162+
return result;
163+
}
164+
165+
#if RN_DEBUG_STRING_CONVERTIBLE
166+
155167
std::string toString(const void* value) {
156168
if (value == nullptr) {
157169
return "null";

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ class DebugStringConvertible {};
8181

8282
#endif
8383

84-
#if RN_DEBUG_STRING_CONVERTIBLE
85-
8684
/*
8785
* Set of particular-format-opinionated functions that convert base types to
8886
* `std::string`
8987
*/
9088
std::string toString(const double &value);
89+
std::string toString(double doubleValue, char suffix);
90+
91+
#if RN_DEBUG_STRING_CONVERTIBLE
92+
9193
std::string toString(const void *value);
9294

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

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,44 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#if RN_DEBUG_STRING_CONVERTIBLE
9-
#include <memory>
8+
#include <limits>
109

1110
#include <gtest/gtest.h>
12-
#include <react/renderer/debug/DebugStringConvertibleItem.h>
11+
#include <react/renderer/debug/DebugStringConvertible.h>
1312

1413
using namespace facebook::react;
1514

15+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffix) {
16+
EXPECT_EQ(toString(3.14, '%'), "3.14%");
17+
EXPECT_EQ(toString(100.0, 'x'), "100x");
18+
}
19+
20+
TEST(DebugStringConvertibleTest, toStringDoubleWithNullSuffix) {
21+
auto result = toString(42.0, '\0');
22+
EXPECT_EQ(result, "42");
23+
}
24+
25+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixZeroValue) {
26+
EXPECT_EQ(toString(0.0, '%'), "0%");
27+
}
28+
29+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixNegativeValue) {
30+
EXPECT_EQ(toString(-2.75, '%'), "-2.75%");
31+
}
32+
33+
TEST(DebugStringConvertibleTest, toStringDoubleWithSuffixSpecialValues) {
34+
EXPECT_EQ(
35+
toString(std::numeric_limits<double>::infinity(), '%'), "Infinity%");
36+
EXPECT_EQ(
37+
toString(-std::numeric_limits<double>::infinity(), '%'), "-Infinity%");
38+
EXPECT_EQ(toString(std::numeric_limits<double>::quiet_NaN(), 'x'), "NaNx");
39+
}
40+
41+
#if RN_DEBUG_STRING_CONVERTIBLE
42+
#include <memory>
43+
44+
#include <react/renderer/debug/DebugStringConvertibleItem.h>
45+
1646
TEST(DebugStringConvertibleTest, handleSimpleNode) {
1747
SharedDebugStringConvertibleList empty;
1848
auto item = std::make_shared<DebugStringConvertibleItem>(
@@ -83,4 +113,5 @@ TEST(DebugStringConvertibleTest, handleNodeWithComplexProps) {
83113
item->getDebugDescription().c_str(),
84114
"<View=hello x=1(height=100 width=200)/>");
85115
}
116+
86117
#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)