[llvm] Eliminate pointless copies (PR #95097)

Tim Gymnich via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 04:42:05 PDT 2024


================
@@ -27,11 +27,10 @@ class MemoryBuffer;
 /// that can be done by deriving from this class and overriding the destructor.
 class CachedFileStream {
 public:
-  CachedFileStream(std::unique_ptr<raw_pwrite_stream> OS,
-                   std::string OSPath = "")
+  CachedFileStream(std::unique_ptr<raw_pwrite_stream> OS, StringRef OSPath = "")
       : OS(std::move(OS)), ObjectPathName(OSPath) {}
   std::unique_ptr<raw_pwrite_stream> OS;
-  std::string ObjectPathName;
----------------
tgymnich wrote:

String constructed for example on the stack may already be freed when using `CachedFileStream` at a later point since `StringRef` does not retain the string here.

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


More information about the llvm-commits mailing list