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
This commit is contained in:
Nicola Corti
2021-08-24 09:53:04 -07:00
committed by Facebook GitHub Bot
parent 7299cb485e
commit a6768bfd70
6 changed files with 0 additions and 44 deletions
@@ -39,9 +39,6 @@ inline RawTextShadowNode const &traitCast<RawTextShadowNode const &>(
ShadowNode const &shadowNode) {
bool castable =
shadowNode.getTraits().check(ShadowNodeTraits::Trait::RawText);
react_native_assert(
castable ==
(dynamic_cast<RawTextShadowNode const *>(&shadowNode) != nullptr));
react_native_assert(castable);
(void)castable;
return static_cast<RawTextShadowNode const &>(shadowNode);
@@ -55,9 +52,6 @@ inline RawTextShadowNode const *traitCast<RawTextShadowNode const *>(
}
bool castable =
shadowNode->getTraits().check(ShadowNodeTraits::Trait::RawText);
react_native_assert(
castable ==
(dynamic_cast<RawTextShadowNode const *>(shadowNode) != nullptr));
if (!castable) {
return nullptr;
}
@@ -62,9 +62,6 @@ template <>
inline TextShadowNode const &traitCast<TextShadowNode const &>(
ShadowNode const &shadowNode) {
bool castable = shadowNode.getTraits().check(ShadowNodeTraits::Trait::Text);
react_native_assert(
castable ==
(dynamic_cast<TextShadowNode const *>(&shadowNode) != nullptr));
react_native_assert(castable);
(void)castable;
return static_cast<TextShadowNode const &>(shadowNode);
@@ -77,9 +74,6 @@ inline TextShadowNode const *traitCast<TextShadowNode const *>(
return nullptr;
}
bool castable = shadowNode->getTraits().check(ShadowNodeTraits::Trait::Text);
react_native_assert(
castable ==
(dynamic_cast<TextShadowNode const *>(shadowNode) != nullptr));
if (!castable) {
return nullptr;
}
@@ -24,13 +24,6 @@ static inline void interpolateViewProps(
const SharedProps &oldPropsShared,
const SharedProps &newPropsShared,
SharedProps &interpolatedPropsShared) {
// Verify the static_casts below are safe
react_native_assert(
dynamic_cast<ViewProps const *>(oldPropsShared.get()) != nullptr &&
dynamic_cast<ViewProps const *>(newPropsShared.get()) != nullptr &&
dynamic_cast<ViewProps const *>(interpolatedPropsShared.get()) !=
nullptr);
ViewProps const *oldViewProps =
static_cast<ViewProps const *>(oldPropsShared.get());
ViewProps const *newViewProps =
@@ -186,9 +186,6 @@ inline YogaLayoutableShadowNode const &
traitCast<YogaLayoutableShadowNode const &>(ShadowNode const &shadowNode) {
bool castable =
shadowNode.getTraits().check(ShadowNodeTraits::Trait::YogaLayoutableKind);
react_native_assert(
castable ==
(dynamic_cast<YogaLayoutableShadowNode const *>(&shadowNode) != nullptr));
react_native_assert(castable);
(void)castable;
return static_cast<YogaLayoutableShadowNode const &>(shadowNode);
@@ -202,9 +199,6 @@ traitCast<YogaLayoutableShadowNode const *>(ShadowNode const *shadowNode) {
}
bool castable = shadowNode->getTraits().check(
ShadowNodeTraits::Trait::YogaLayoutableKind);
react_native_assert(
castable ==
(dynamic_cast<YogaLayoutableShadowNode const *>(shadowNode) != nullptr));
if (!castable) {
return nullptr;
}
@@ -79,10 +79,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
ShadowNode::Unshared cloneShadowNode(
const ShadowNode &sourceShadowNode,
const ShadowNodeFragment &fragment) const override {
react_native_assert(
dynamic_cast<ConcreteShadowNode const *>(&sourceShadowNode) &&
"Provided `sourceShadowNode` has an incompatible type.");
auto shadowNode = std::make_shared<ShadowNodeT>(sourceShadowNode, fragment);
adopt(shadowNode);
@@ -92,10 +88,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
void appendChild(
const ShadowNode::Shared &parentShadowNode,
const ShadowNode::Shared &childShadowNode) const override {
react_native_assert(
dynamic_cast<ConcreteShadowNode const *>(parentShadowNode.get()) &&
"Provided `parentShadowNode` has an incompatible type.");
auto concreteParentShadowNode =
std::static_pointer_cast<const ShadowNodeT>(parentShadowNode);
auto concreteNonConstParentShadowNode =
@@ -107,11 +99,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
const PropsParserContext &context,
const SharedProps &props,
const RawProps &rawProps) const override {
react_native_assert(
!props ||
dynamic_cast<ConcreteProps const *>(props.get()) &&
"Provided `props` has an incompatible type.");
// Optimization:
// Quite often nodes are constructed with default/empty props: the base
// `props` object is `null` (there no base because it's not cloning) and the
@@ -170,9 +170,6 @@ inline LayoutableShadowNode const &traitCast<LayoutableShadowNode const &>(
ShadowNode const &shadowNode) {
bool castable =
shadowNode.getTraits().check(ShadowNodeTraits::Trait::LayoutableKind);
react_native_assert(
castable ==
(dynamic_cast<LayoutableShadowNode const *>(&shadowNode) != nullptr));
react_native_assert(castable);
(void)castable;
return static_cast<LayoutableShadowNode const &>(shadowNode);
@@ -186,9 +183,6 @@ inline LayoutableShadowNode const *traitCast<LayoutableShadowNode const *>(
}
bool castable =
shadowNode->getTraits().check(ShadowNodeTraits::Trait::LayoutableKind);
react_native_assert(
castable ==
(dynamic_cast<LayoutableShadowNode const *>(shadowNode) != nullptr));
if (!castable) {
return nullptr;
}