On 05/24/2016 08:33 AM, jww...@mozilla.com wrote:
For
RefPtr<T> GetFoo() {
RefPtr<T> foo;
// ...
}
should we:
1. return foo and expect RVO to kick in to eliminate additional AddRef/Release
2. return foo.forget()
3. return Move(foo)
Which one is preferred?
ps: I find gcc is able to apply RVO even with "-O0". Not sure if it is also
true for other compilers.
Can we somehow guarantee that RVO kicks in? It feels quite error prone to rely
on compiler optimization when dealing with
possibly slow Addref/Release calls.
https://en.wikipedia.org/wiki/Return_value_optimization#Compiler_support hints
that there are cases when RVO might not happen.
-Olli
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform