Skip to content

Commit

Permalink
Fabric: Getting rid of static_pointer_cast in ConcreteShadowNode
Browse files Browse the repository at this point in the history
Summary:
`std::static_pointer_cast` has perf overhead where as `static_cast` does not.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19837695

fbshipit-source-id: 4a257e66813a4a3c757c8ea15ea6ae5e192d1390
  • Loading branch information
shergin authored and facebook-github-bot committed Feb 14, 2020
1 parent 967c9dc commit 5703abd
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class ConcreteShadowNode : public ShadowNode {
using ShadowNode::ShadowNode;

using ConcreteProps = PropsT;
using SharedConcreteProps = std::shared_ptr<const PropsT>;
using SharedConcreteProps = std::shared_ptr<PropsT const>;
using ConcreteEventEmitter = EventEmitterT;
using SharedConcreteEventEmitter = std::shared_ptr<const EventEmitterT>;
using SharedConcreteShadowNode = std::shared_ptr<const ConcreteShadowNode>;
using SharedConcreteEventEmitter = std::shared_ptr<EventEmitterT const>;
using SharedConcreteShadowNode = std::shared_ptr<ConcreteShadowNode const>;
using ConcreteState = ConcreteState<StateDataT>;
using ConcreteStateData = StateDataT;

Expand All @@ -59,11 +59,10 @@ class ConcreteShadowNode : public ShadowNode {
}

static SharedConcreteProps Props(
const RawProps &rawProps,
const SharedProps &baseProps = nullptr) {
return std::make_shared<const PropsT>(
baseProps ? *std::static_pointer_cast<const PropsT>(baseProps)
: PropsT(),
RawProps const &rawProps,
SharedProps const &baseProps = nullptr) {
return std::make_shared<PropsT const>(
baseProps ? static_cast<PropsT const &>(*baseProps) : PropsT(),
rawProps);
}

Expand All @@ -89,7 +88,7 @@ class ConcreteShadowNode : public ShadowNode {
assert(
std::dynamic_pointer_cast<ConcreteProps const>(props_) &&
"Props must be an instance of ConcreteProps class.");
return *static_cast<ConcreteProps const *>(props_.get());
return static_cast<ConcreteProps const &>(*props_);
}

/*
Expand All @@ -101,7 +100,7 @@ class ConcreteShadowNode : public ShadowNode {
assert(
std::dynamic_pointer_cast<ConcreteState const>(state_) &&
"State must be an instance of ConcreteState class.");
return std::static_pointer_cast<ConcreteState const>(state_)->getData();
return static_cast<ConcreteState const *>(state_.get())->getData();
}

/*
Expand All @@ -124,9 +123,9 @@ class ConcreteShadowNode : public ShadowNode {
better::
small_vector<SpecificShadowNodeT *, kShadowNodeChildrenSmallVectorSize>
children;
for (const auto &childShadowNode : getChildren()) {
for (auto const &childShadowNode : getChildren()) {
auto specificChildShadowNode =
dynamic_cast<const SpecificShadowNodeT *>(childShadowNode.get());
dynamic_cast<SpecificShadowNodeT const *>(childShadowNode.get());
if (specificChildShadowNode) {
children.push_back(
const_cast<SpecificShadowNodeT *>(specificChildShadowNode));
Expand Down

0 comments on commit 5703abd

Please sign in to comment.