Passing by reference avoids reference counter increment so it may be faster (especially if you do it a lot in a highly multithreaded application) though the code may be considered a bit more confusing. Especially since, if you pass by reference, the method can change the shared pointer which could be a surprising behaviour; in this case you probably would want to a const reference. Then again, passing by reference stacks pointers on top of pointers so dereference could potentially be slower. Performance is hard to reason about in abstract.
As an aside, if you want to give away ownership of the object and pass it to the method, std::move the value and use &&.
Last edited by mina86; 10-09-2018 at 04:13 AM.
|