[llvm] fixed #95641 pointless string copy (PR #127325)

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 15 06:01:56 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: sommersun (sommersun)

<details>
<summary>Changes</summary>

fixed #<!-- -->95641 by using std::move for T&&.  

---
Full diff: https://github.com/llvm/llvm-project/pull/127325.diff


2 Files Affected:

- (modified) llvm/include/llvm/TableGen/Record.h (+2-1) 
- (modified) llvm/lib/TableGen/Main.cpp (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index e04ed34823148..08d8e2a94c0aa 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -142,6 +142,7 @@ class BitsRecTy : public RecTy {
 
   unsigned getNumBits() const { return Size; }
 
+
   std::string getAsString() const override;
 
   bool typeIsConvertibleTo(const RecTy *RHS) const override;
@@ -1966,7 +1967,7 @@ class RecordKeeper {
     return It == ExtraGlobals.end() ? nullptr : It->second;
   }
 
-  void saveInputFilename(std::string Filename) {
+  void saveInputFilename(std::string && Filename) {
     InputFilename = Filename;
   }
 
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index 35600bf2f1f86..81b2e81dc6064 100644
--- a/llvm/lib/TableGen/Main.cpp
+++ b/llvm/lib/TableGen/Main.cpp
@@ -113,7 +113,7 @@ int llvm::TableGenMain(const char *argv0,
     return reportError(argv0, "Could not open input file '" + InputFilename +
                                   "': " + EC.message() + "\n");
 
-  Records.saveInputFilename(InputFilename);
+  Records.saveInputFilename(std::move(InputFilename));
 
   // Tell SrcMgr about this buffer, which is what TGParser will pick up.
   SrcMgr.AddNewSourceBuffer(std::move(*FileOrErr), SMLoc());

``````````

</details>


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


More information about the llvm-commits mailing list