Use unique_ptr instead of shared_ptr in activeAnimations_ (#51587)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51587

changelog: [internal]

use unique_ptr instead of shared_ptr to manage memory of activeAnimations_.

Active animations are only owned by NativeAnimatedNodesManager and their ownership isn't shared with any other class.

This saves a little bit of C++ binary size.

Reviewed By: rshest

Differential Revision: D75142643

fbshipit-source-id: c09753b68e70e95fedcb7b2b8fb19a0fd7010059
This commit is contained in:
Samuel Susla
2025-05-25 04:20:59 -07:00
committed by Facebook GitHub Bot
parent 1e31392211
commit 1db4874bb3
2 changed files with 7 additions and 7 deletions
@@ -299,30 +299,30 @@ void NativeAnimatedNodesManager::startAnimatingNode(
if (auto iter = activeAnimations_.find(animationId);
iter != activeAnimations_.end()) {
// reset animation config
auto animation = iter->second;
auto& animation = iter->second;
animation->updateConfig(config);
} else if (animatedNodes_.contains(animatedNodeTag)) {
auto type = config["type"].asString();
auto typeEnum = AnimationDriver::getDriverTypeByName(type);
std::shared_ptr<AnimationDriver> animation = nullptr;
std::unique_ptr<AnimationDriver> animation = nullptr;
if (typeEnum) {
switch (typeEnum.value()) {
case AnimationDriverType::Frames: {
animation = std::make_shared<FrameAnimationDriver>(
animation = std::make_unique<FrameAnimationDriver>(
animationId, animatedNodeTag, endCallback, config, this);
} break;
case AnimationDriverType::Spring: {
animation = std::make_shared<SpringAnimationDriver>(
animation = std::make_unique<SpringAnimationDriver>(
animationId, animatedNodeTag, endCallback, config, this);
} break;
case AnimationDriverType::Decay: {
animation = std::make_shared<DecayAnimationDriver>(
animation = std::make_unique<DecayAnimationDriver>(
animationId, animatedNodeTag, endCallback, config, this);
} break;
}
if (animation) {
activeAnimations_.insert({animationId, animation});
animation->startAnimation();
activeAnimations_.insert({animationId, std::move(animation)});
}
} else {
LOG(ERROR) << "Unknown AnimationDriver type " << type;
@@ -197,7 +197,7 @@ class NativeAnimatedNodesManager
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>> animatedNodes_;
std::unordered_map<Tag, Tag> connectedAnimatedNodes_;
std::unordered_map<int, std::shared_ptr<AnimationDriver>> activeAnimations_;
std::unordered_map<int, std::unique_ptr<AnimationDriver>> activeAnimations_;
std::unordered_map<
EventAnimationDriverKey,
std::vector<std::unique_ptr<EventAnimationDriver>>,