On Fri, May 15, 2015 at 04:58:24PM +0200, Stephan Witt wrote: > Am 15.05.2015 um 16:48 schrieb Enrico Forestieri <[email protected]>: > > > On Fri, May 15, 2015 at 04:31:05PM +0200, Stephan Witt wrote: > >> > >> This results in the following patch - if you had something like that in > >> mind I'll split it in two patches. The other getPixmap method with > >> QPixmap result was already there. > > > > Yes, I think that it is better passing big objects by reference rather > > than by value. > > But this is not a good property of C++ compilers than. > 1. It's not a constant fact if an object is big. > 2. The compiler should generate fast code for this scenario too. > 3. This results in hard to read code eventually.
You are probably right and it seems people prefer the simpler approach by relying on the return value optimization performed by modern compilers. http://stackoverflow.com/questions/753312/returning-large-objects-in-functions http://stackoverflow.com/questions/4809120/creating-and-returning-a-big-object-from-a-function http://stackoverflow.com/questions/24685054/how-do-c-functions-return-a-big-object-or-a-structure What triggered my comment was seeing that call in a loop, so you could simply limit the change to that one function and leave the rest as is. Or you could also disregard that comment ;-) -- Enrico
