[llvm] [llvm][CodeGen] Avoid 'raw_string_ostream::str' (NFC) (PR #97318)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 5 17:55:08 PDT 2024


kepler-5 wrote:

For my context (I'm the blame on the TODO comment to remove `str()`), my original motivation was to optimize common uses such as:
```
std::string S;
raw_string_ostream OS(S);
OS << "hello";
return OS.str(); // copies S
```
Returning `.str()` involves a copy, whereas `return S;` gets NRVO or implicit move.

While I believe this optimization is compelling (as is the memory safety argument), IIRC the TODO comment to remove .str() entirely was at the request of the folks who reviewed my code, and I can't personally attest that it's the right direction for the class at this point in time a couple years later.

https://github.com/llvm/llvm-project/pull/97318


More information about the llvm-commits mailing list