Skip to content

Commit 3218680

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Avoid redundant copy of shared_ptr
Summary: changelog: [internal] Making a copy of shared_ptr is order of magnitude more expensive than moving it. This diff avoids two redundant copies in commit phase. Reviewed By: rubennorte, cipolleschi Differential Revision: D43306245 fbshipit-source-id: cfa942cc67b1e5c91be47803b80f7c8cda2e32d8
1 parent 1f151e0 commit 3218680

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

ReactCommon/react/renderer/mounting/MountingCoordinator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ SurfaceId MountingCoordinator::getSurfaceId() const {
3333
return surfaceId_;
3434
}
3535

36-
void MountingCoordinator::push(ShadowTreeRevision const &revision) const {
36+
void MountingCoordinator::push(ShadowTreeRevision revision) const {
3737
{
3838
std::lock_guard<std::mutex> lock(mutex_);
3939

4040
react_native_assert(
4141
!lastRevision_.has_value() || revision.number != lastRevision_->number);
4242

4343
if (!lastRevision_.has_value() || lastRevision_->number < revision.number) {
44-
lastRevision_ = revision;
44+
lastRevision_ = std::move(revision);
4545
}
4646
}
4747

ReactCommon/react/renderer/mounting/MountingCoordinator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class MountingCoordinator final {
8888
private:
8989
friend class ShadowTree;
9090

91-
void push(ShadowTreeRevision const &revision) const;
91+
void push(ShadowTreeRevision revision) const;
9292

9393
/*
9494
* Revokes the last pushed `ShadowTreeRevision`.

ReactCommon/react/renderer/mounting/ShadowTree.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,16 @@ CommitStatus ShadowTree::tryCommit(
393393
telemetry.didCommit();
394394
telemetry.setRevisionNumber(static_cast<int>(newRevisionNumber));
395395

396-
newRevision =
397-
ShadowTreeRevision{newRootShadowNode, newRevisionNumber, telemetry};
396+
newRevision = ShadowTreeRevision{
397+
std::move(newRootShadowNode), newRevisionNumber, telemetry};
398398

399399
currentRevision_ = newRevision;
400400
}
401401

402402
emitLayoutEvents(affectedLayoutableNodes);
403403

404404
if (commitMode == CommitMode::Normal) {
405-
mount(newRevision, commitOptions.mountSynchronously);
405+
mount(std::move(newRevision), commitOptions.mountSynchronously);
406406
}
407407

408408
return CommitStatus::Succeeded;
@@ -413,10 +413,9 @@ ShadowTreeRevision ShadowTree::getCurrentRevision() const {
413413
return currentRevision_;
414414
}
415415

416-
void ShadowTree::mount(
417-
ShadowTreeRevision const &revision,
418-
bool mountSynchronously) const {
419-
mountingCoordinator_->push(revision);
416+
void ShadowTree::mount(ShadowTreeRevision revision, bool mountSynchronously)
417+
const {
418+
mountingCoordinator_->push(std::move(revision));
420419
delegate_.shadowTreeDidFinishTransaction(
421420
mountingCoordinator_, mountSynchronously);
422421
}

ReactCommon/react/renderer/mounting/ShadowTree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ShadowTree final {
134134
private:
135135
constexpr static ShadowTreeRevision::Number INITIAL_REVISION{0};
136136

137-
void mount(ShadowTreeRevision const &revision, bool mountSynchronously) const;
137+
void mount(ShadowTreeRevision revision, bool mountSynchronously) const;
138138

139139
void emitLayoutEvents(
140140
std::vector<LayoutableShadowNode const *> &affectedLayoutableNodes) const;

0 commit comments

Comments
 (0)