Skip to content

Commit 1e31392

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
remove use of shared_ptr from NativeAnimatedNodesManager::animatedNodes_ and NodesQueueItem (#51586)
Summary: Pull Request resolved: #51586 changelog: [internal] using shared_ptr here is not necessary because AnimatedNodes are not shared between multiple entities, they are only owned by NativeAnimatedNodesManager. This saves a little bit C++ binary size. Reviewed By: rshest Differential Revision: D75148952 fbshipit-source-id: 18b8231061cda970ad96842ee6ca3135c2ec5d68
1 parent afb5436 commit 1e31392

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace facebook::react {
3838
namespace {
3939

4040
struct NodesQueueItem {
41-
std::shared_ptr<AnimatedNode> node;
41+
AnimatedNode* node;
4242
bool connectedToFinishedAnimation;
4343
};
4444

@@ -489,7 +489,7 @@ void NativeAnimatedNodesManager::updateNodes(
489489

490490
const auto is_node_connected_to_finished_animation =
491491
[&finishedAnimationValueNodes](
492-
const std::shared_ptr<AnimatedNode>& node,
492+
AnimatedNode* node,
493493
int nodeTag,
494494
bool parentFinishedAnimation) -> bool {
495495
return parentFinishedAnimation ||
@@ -522,7 +522,7 @@ void NativeAnimatedNodesManager::updateNodes(
522522
const auto connectedToFinishedAnimation =
523523
is_node_connected_to_finished_animation(node, nodeTag, false);
524524
nodesQueue.emplace_back(
525-
NodesQueueItem{std::move(node), connectedToFinishedAnimation});
525+
NodesQueueItem{node, connectedToFinishedAnimation});
526526
}
527527
}
528528
}
@@ -544,7 +544,7 @@ void NativeAnimatedNodesManager::updateNodes(
544544
is_node_connected_to_finished_animation(
545545
child, childTag, nextNode.connectedToFinishedAnimation);
546546
nodesQueue.emplace_back(
547-
NodesQueueItem{std::move(child), connectedToFinishedAnimation});
547+
NodesQueueItem{child, connectedToFinishedAnimation});
548548
}
549549
}
550550
}
@@ -575,7 +575,7 @@ void NativeAnimatedNodesManager::updateNodes(
575575
const auto connectedToFinishedAnimation =
576576
is_node_connected_to_finished_animation(node, nodeTag, false);
577577
nodesQueue.emplace_back(
578-
NodesQueueItem{std::move(node), connectedToFinishedAnimation});
578+
NodesQueueItem{node, connectedToFinishedAnimation});
579579
}
580580
}
581581
}
@@ -589,8 +589,7 @@ void NativeAnimatedNodesManager::updateNodes(
589589
nodesQueue.pop_front();
590590
if (nextNode.connectedToFinishedAnimation &&
591591
nextNode.node->type() == AnimatedNodeType::Props) {
592-
if (auto propsNode =
593-
std::static_pointer_cast<PropsAnimatedNode>(nextNode.node)) {
592+
if (auto propsNode = dynamic_cast<PropsAnimatedNode*>(nextNode.node)) {
594593
propsNode->update(/*forceFabricCommit*/ true);
595594
};
596595
} else {
@@ -609,7 +608,7 @@ void NativeAnimatedNodesManager::updateNodes(
609608
is_node_connected_to_finished_animation(
610609
child, childTag, nextNode.connectedToFinishedAnimation);
611610
nodesQueue.emplace_back(
612-
NodesQueueItem{std::move(child), connectedToFinishedAnimation});
611+
NodesQueueItem{child, connectedToFinishedAnimation});
613612
}
614613
#ifdef REACT_NATIVE_DEBUG
615614
else if (child->bfsColor == animatedGraphBFSColor_) {
@@ -706,7 +705,7 @@ void NativeAnimatedNodesManager::startListeningToAnimatedNodeValue(
706705
ValueListenerCallback&& callback) noexcept {
707706
if (auto iter = animatedNodes_.find(tag); iter != animatedNodes_.end() &&
708707
iter->second->type() == AnimatedNodeType::Value) {
709-
static_pointer_cast<ValueAnimatedNode>(iter->second)
708+
static_cast<ValueAnimatedNode*>(iter->second.get())
710709
->setValueListener(std::move(callback));
711710
} else {
712711
LOG(ERROR) << "startListeningToAnimatedNodeValue: Animated node [" << tag
@@ -718,7 +717,7 @@ void NativeAnimatedNodesManager::stopListeningToAnimatedNodeValue(
718717
Tag tag) noexcept {
719718
if (auto iter = animatedNodes_.find(tag); iter != animatedNodes_.end() &&
720719
iter->second->type() == AnimatedNodeType::Value) {
721-
static_pointer_cast<ValueAnimatedNode>(iter->second)
720+
static_cast<ValueAnimatedNode*>(iter->second.get())
722721
->setValueListener(nullptr);
723722
} else {
724723
LOG(ERROR) << "stopListeningToAnimatedNodeValue: Animated node [" << tag

packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class NativeAnimatedNodesManager
6262
template <
6363
typename T,
6464
typename = std::enable_if_t<std::is_base_of_v<AnimatedNode, T>>>
65-
std::shared_ptr<T> getAnimatedNode(Tag tag) const
65+
T* getAnimatedNode(Tag tag) const
6666
requires(std::is_base_of_v<AnimatedNode, T>)
6767
{
6868
if (auto it = animatedNodes_.find(tag); it != animatedNodes_.end()) {
69-
return std::static_pointer_cast<T>(it->second);
69+
return static_cast<T*>(it->second.get());
7070
}
7171
return nullptr;
7272
}
@@ -195,7 +195,7 @@ class NativeAnimatedNodesManager
195195
Tag tag,
196196
const folly::dynamic& config) noexcept;
197197

198-
std::unordered_map<Tag, std::shared_ptr<AnimatedNode>> animatedNodes_;
198+
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>> animatedNodes_;
199199
std::unordered_map<Tag, Tag> connectedAnimatedNodes_;
200200
std::unordered_map<int, std::shared_ptr<AnimationDriver>> activeAnimations_;
201201
std::unordered_map<

packages/react-native/ReactCxxPlatform/react/renderer/animated/nodes/AnimatedNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void AnimatedNode::removeChild(const Tag tag) {
3535
}
3636
}
3737

38-
std::shared_ptr<AnimatedNode> AnimatedNode::getChildNode(Tag tag) {
38+
AnimatedNode* AnimatedNode::getChildNode(Tag tag) {
3939
if (const auto manager = manager_.lock()) {
4040
if (children_.find(tag) != children_.end()) {
4141
return manager->getAnimatedNode<AnimatedNode>(tag);

packages/react-native/ReactCxxPlatform/react/renderer/animated/nodes/AnimatedNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class AnimatedNode {
9797
static constexpr int INITIAL_BFS_COLOR = 0;
9898

9999
protected:
100-
std::shared_ptr<AnimatedNode> getChildNode(Tag tag);
100+
AnimatedNode* getChildNode(Tag tag);
101101
Tag tag_{0};
102102
std::weak_ptr<NativeAnimatedNodesManager> manager_;
103103
AnimatedNodeType type_;

0 commit comments

Comments
 (0)