PragmaTwice opened a new issue, #581: URL: https://github.com/apache/incubator-kvrocks/issues/581
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/incubator-kvrocks/issues) and found no similar issues. ### Motivation C++ specifies a number of strategies in the standard to eliminate unnecessary copies, which are called [copy elision](https://en.cppreference.com/w/cpp/language/copy_elision). One of these optimizations is called *named return value optimization* (NRVO), which is defined in the standard. This optimization works on the return value, in short, the returned object is not copied onto the current stack. GCC and Clang both perform this optimization by default (even in the `-O0` case). The following simple code demonstrates it: ```c++ T f() { T a; ... // operations on a return a; } T a = f(); // T::T(const T&) or T::T(T&&) will not be called ``` You can view the assembly or modify and execute this code online on [godbolt](https://godbolt.org/z/49TWE6j9Y). So passing pointers to optimize efficiency is usually not necessary, and returning values is usually easier to make the operation be expressed in the same expression and more intuitive. Some parts of this project use this approach, like [these functions](https://github.com/apache/incubator-kvrocks/blob/unstable/src/util.h#L79-L81). So I think it would be better to change them to return the results directly. ### Solution _No response_ ### Are you willing to submit a PR? - [X] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
