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
This commit is contained in:
Samuel Susla
2023-02-16 13:42:26 -08:00
committed by Facebook GitHub Bot
parent 1f151e0d2f
commit 321868011b
4 changed files with 10 additions and 11 deletions
@@ -33,7 +33,7 @@ SurfaceId MountingCoordinator::getSurfaceId() const {
return surfaceId_;
}
void MountingCoordinator::push(ShadowTreeRevision const &revision) const {
void MountingCoordinator::push(ShadowTreeRevision revision) const {
{
std::lock_guard<std::mutex> lock(mutex_);
@@ -41,7 +41,7 @@ void MountingCoordinator::push(ShadowTreeRevision const &revision) const {
!lastRevision_.has_value() || revision.number != lastRevision_->number);
if (!lastRevision_.has_value() || lastRevision_->number < revision.number) {
lastRevision_ = revision;
lastRevision_ = std::move(revision);
}
}
@@ -88,7 +88,7 @@ class MountingCoordinator final {
private:
friend class ShadowTree;
void push(ShadowTreeRevision const &revision) const;
void push(ShadowTreeRevision revision) const;
/*
* Revokes the last pushed `ShadowTreeRevision`.
@@ -393,8 +393,8 @@ CommitStatus ShadowTree::tryCommit(
telemetry.didCommit();
telemetry.setRevisionNumber(static_cast<int>(newRevisionNumber));
newRevision =
ShadowTreeRevision{newRootShadowNode, newRevisionNumber, telemetry};
newRevision = ShadowTreeRevision{
std::move(newRootShadowNode), newRevisionNumber, telemetry};
currentRevision_ = newRevision;
}
@@ -402,7 +402,7 @@ CommitStatus ShadowTree::tryCommit(
emitLayoutEvents(affectedLayoutableNodes);
if (commitMode == CommitMode::Normal) {
mount(newRevision, commitOptions.mountSynchronously);
mount(std::move(newRevision), commitOptions.mountSynchronously);
}
return CommitStatus::Succeeded;
@@ -413,10 +413,9 @@ ShadowTreeRevision ShadowTree::getCurrentRevision() const {
return currentRevision_;
}
void ShadowTree::mount(
ShadowTreeRevision const &revision,
bool mountSynchronously) const {
mountingCoordinator_->push(revision);
void ShadowTree::mount(ShadowTreeRevision revision, bool mountSynchronously)
const {
mountingCoordinator_->push(std::move(revision));
delegate_.shadowTreeDidFinishTransaction(
mountingCoordinator_, mountSynchronously);
}
@@ -134,7 +134,7 @@ class ShadowTree final {
private:
constexpr static ShadowTreeRevision::Number INITIAL_REVISION{0};
void mount(ShadowTreeRevision const &revision, bool mountSynchronously) const;
void mount(ShadowTreeRevision revision, bool mountSynchronously) const;
void emitLayoutEvents(
std::vector<LayoutableShadowNode const *> &affectedLayoutableNodes) const;