Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question: Is the main reason that we don't
std::move
the listener pointer on remove because we no longer care about reference counts when it's about to be deleted?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving is only useful when the parameter is accepted by value (or by rvalue reference). This gives the caller's copy away.
In this case,
RemoveSnapshotsInSyncListener
takes a const reference to theuser_listener
so moving doesn't do anything, but it's not bumping the reference count anyway.https://github.com/firebase/firebase-ios-sdk/blob/master/Firestore/core/src/core/event_manager.h#L68
To answer your follow-up question,
RemoveSnapshotsInSyncListener
takes the listener by const reference because it's not going to store the listener anyway. It's uses the reference passed to find associated data but forgets about it immediately. You only want to take something like that by value if your method will keep it. In that case std::move in the caller gives the caller's copy away.