Skip to content

Commit a6768bf

Browse files
cortinicofacebook-github-bot
authored andcommitted
Remove usages of dynamic_casts that are used inside assertions
Summary: This diff is part of a bigger effort to remove the RTTI flags. To do so we need to remove occurrences of `dynamic_cast` and other functions that rely on runtime type informations. Changelog: [Internal][Changed] - Removed extra asserts relying on dynamic_cast Reviewed By: JoshuaGross Differential Revision: D30483554 fbshipit-source-id: 92b31281841a92c7b43e918938248431265dd654
1 parent 7299cb4 commit a6768bf

File tree

6 files changed

+0
-44
lines changed

6 files changed

+0
-44
lines changed

Diff for: ReactCommon/react/renderer/components/text/RawTextShadowNode.h

-6
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ inline RawTextShadowNode const &traitCast<RawTextShadowNode const &>(
3939
ShadowNode const &shadowNode) {
4040
bool castable =
4141
shadowNode.getTraits().check(ShadowNodeTraits::Trait::RawText);
42-
react_native_assert(
43-
castable ==
44-
(dynamic_cast<RawTextShadowNode const *>(&shadowNode) != nullptr));
4542
react_native_assert(castable);
4643
(void)castable;
4744
return static_cast<RawTextShadowNode const &>(shadowNode);
@@ -55,9 +52,6 @@ inline RawTextShadowNode const *traitCast<RawTextShadowNode const *>(
5552
}
5653
bool castable =
5754
shadowNode->getTraits().check(ShadowNodeTraits::Trait::RawText);
58-
react_native_assert(
59-
castable ==
60-
(dynamic_cast<RawTextShadowNode const *>(shadowNode) != nullptr));
6155
if (!castable) {
6256
return nullptr;
6357
}

Diff for: ReactCommon/react/renderer/components/text/TextShadowNode.h

-6
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ template <>
6262
inline TextShadowNode const &traitCast<TextShadowNode const &>(
6363
ShadowNode const &shadowNode) {
6464
bool castable = shadowNode.getTraits().check(ShadowNodeTraits::Trait::Text);
65-
react_native_assert(
66-
castable ==
67-
(dynamic_cast<TextShadowNode const *>(&shadowNode) != nullptr));
6865
react_native_assert(castable);
6966
(void)castable;
7067
return static_cast<TextShadowNode const &>(shadowNode);
@@ -77,9 +74,6 @@ inline TextShadowNode const *traitCast<TextShadowNode const *>(
7774
return nullptr;
7875
}
7976
bool castable = shadowNode->getTraits().check(ShadowNodeTraits::Trait::Text);
80-
react_native_assert(
81-
castable ==
82-
(dynamic_cast<TextShadowNode const *>(shadowNode) != nullptr));
8377
if (!castable) {
8478
return nullptr;
8579
}

Diff for: ReactCommon/react/renderer/components/view/ViewPropsInterpolation.h

-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ static inline void interpolateViewProps(
2424
const SharedProps &oldPropsShared,
2525
const SharedProps &newPropsShared,
2626
SharedProps &interpolatedPropsShared) {
27-
// Verify the static_casts below are safe
28-
react_native_assert(
29-
dynamic_cast<ViewProps const *>(oldPropsShared.get()) != nullptr &&
30-
dynamic_cast<ViewProps const *>(newPropsShared.get()) != nullptr &&
31-
dynamic_cast<ViewProps const *>(interpolatedPropsShared.get()) !=
32-
nullptr);
33-
3427
ViewProps const *oldViewProps =
3528
static_cast<ViewProps const *>(oldPropsShared.get());
3629
ViewProps const *newViewProps =

Diff for: ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h

-6
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ inline YogaLayoutableShadowNode const &
186186
traitCast<YogaLayoutableShadowNode const &>(ShadowNode const &shadowNode) {
187187
bool castable =
188188
shadowNode.getTraits().check(ShadowNodeTraits::Trait::YogaLayoutableKind);
189-
react_native_assert(
190-
castable ==
191-
(dynamic_cast<YogaLayoutableShadowNode const *>(&shadowNode) != nullptr));
192189
react_native_assert(castable);
193190
(void)castable;
194191
return static_cast<YogaLayoutableShadowNode const &>(shadowNode);
@@ -202,9 +199,6 @@ traitCast<YogaLayoutableShadowNode const *>(ShadowNode const *shadowNode) {
202199
}
203200
bool castable = shadowNode->getTraits().check(
204201
ShadowNodeTraits::Trait::YogaLayoutableKind);
205-
react_native_assert(
206-
castable ==
207-
(dynamic_cast<YogaLayoutableShadowNode const *>(shadowNode) != nullptr));
208202
if (!castable) {
209203
return nullptr;
210204
}

Diff for: ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

-13
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
7979
ShadowNode::Unshared cloneShadowNode(
8080
const ShadowNode &sourceShadowNode,
8181
const ShadowNodeFragment &fragment) const override {
82-
react_native_assert(
83-
dynamic_cast<ConcreteShadowNode const *>(&sourceShadowNode) &&
84-
"Provided `sourceShadowNode` has an incompatible type.");
85-
8682
auto shadowNode = std::make_shared<ShadowNodeT>(sourceShadowNode, fragment);
8783

8884
adopt(shadowNode);
@@ -92,10 +88,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
9288
void appendChild(
9389
const ShadowNode::Shared &parentShadowNode,
9490
const ShadowNode::Shared &childShadowNode) const override {
95-
react_native_assert(
96-
dynamic_cast<ConcreteShadowNode const *>(parentShadowNode.get()) &&
97-
"Provided `parentShadowNode` has an incompatible type.");
98-
9991
auto concreteParentShadowNode =
10092
std::static_pointer_cast<const ShadowNodeT>(parentShadowNode);
10193
auto concreteNonConstParentShadowNode =
@@ -107,11 +99,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
10799
const PropsParserContext &context,
108100
const SharedProps &props,
109101
const RawProps &rawProps) const override {
110-
react_native_assert(
111-
!props ||
112-
dynamic_cast<ConcreteProps const *>(props.get()) &&
113-
"Provided `props` has an incompatible type.");
114-
115102
// Optimization:
116103
// Quite often nodes are constructed with default/empty props: the base
117104
// `props` object is `null` (there no base because it's not cloning) and the

Diff for: ReactCommon/react/renderer/core/LayoutableShadowNode.h

-6
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ inline LayoutableShadowNode const &traitCast<LayoutableShadowNode const &>(
170170
ShadowNode const &shadowNode) {
171171
bool castable =
172172
shadowNode.getTraits().check(ShadowNodeTraits::Trait::LayoutableKind);
173-
react_native_assert(
174-
castable ==
175-
(dynamic_cast<LayoutableShadowNode const *>(&shadowNode) != nullptr));
176173
react_native_assert(castable);
177174
(void)castable;
178175
return static_cast<LayoutableShadowNode const &>(shadowNode);
@@ -186,9 +183,6 @@ inline LayoutableShadowNode const *traitCast<LayoutableShadowNode const *>(
186183
}
187184
bool castable =
188185
shadowNode->getTraits().check(ShadowNodeTraits::Trait::LayoutableKind);
189-
react_native_assert(
190-
castable ==
191-
(dynamic_cast<LayoutableShadowNode const *>(shadowNode) != nullptr));
192186
if (!castable) {
193187
return nullptr;
194188
}

0 commit comments

Comments
 (0)