[llvm] f6799d2 - [NFC][LLVM][Twine] Change a few `const StringRef &` arguments to value (#163994)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Oct 21 13:47:00 PDT 2025
    
    
  
Author: Rahul Joshi
Date: 2025-10-21T13:46:56-07:00
New Revision: f6799d2899ef689a5e4d55beef9b52914d2ae95f
URL: https://github.com/llvm/llvm-project/commit/f6799d2899ef689a5e4d55beef9b52914d2ae95f
DIFF: https://github.com/llvm/llvm-project/commit/f6799d2899ef689a5e4d55beef9b52914d2ae95f.diff
LOG: [NFC][LLVM][Twine] Change a few `const StringRef &` arguments to value (#163994)
Per LLVM Programmer's Manual, StringRef should always be passed by
value. Enforcing this for `Twine` functions.
Added: 
    
Modified: 
    llvm/include/llvm/ADT/Twine.h
Removed: 
    
################################################################################
diff  --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index d9f9c0f0d5d9c..e3b4d5e26fa17 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -285,7 +285,7 @@ class Twine {
   }
 
   /// Construct from a StringRef.
-  /*implicit*/ Twine(const StringRef &Str) : LHSKind(PtrAndLengthKind) {
+  /*implicit*/ Twine(StringRef Str) : LHSKind(PtrAndLengthKind) {
     LHS.ptrAndLength.ptr = Str.data();
     LHS.ptrAndLength.length = Str.size();
     assert(isValid() && "Invalid twine!");
@@ -352,7 +352,7 @@ class Twine {
   // right thing. Yet.
 
   /// Construct as the concatenation of a C string and a StringRef.
-  /*implicit*/ Twine(const char *LHS, const StringRef &RHS)
+  /*implicit*/ Twine(const char *LHS, StringRef RHS)
       : LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
     this->LHS.cString = LHS;
     this->RHS.ptrAndLength.ptr = RHS.data();
@@ -361,7 +361,7 @@ class Twine {
   }
 
   /// Construct as the concatenation of a StringRef and a C string.
-  /*implicit*/ Twine(const StringRef &LHS, const char *RHS)
+  /*implicit*/ Twine(StringRef LHS, const char *RHS)
       : LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
     this->LHS.ptrAndLength.ptr = LHS.data();
     this->LHS.ptrAndLength.length = LHS.size();
@@ -530,14 +530,14 @@ inline Twine operator+(const Twine &LHS, const Twine &RHS) {
 /// Additional overload to guarantee simplified codegen; this is equivalent to
 /// concat().
 
-inline Twine operator+(const char *LHS, const StringRef &RHS) {
+inline Twine operator+(const char *LHS, StringRef RHS) {
   return Twine(LHS, RHS);
 }
 
 /// Additional overload to guarantee simplified codegen; this is equivalent to
 /// concat().
 
-inline Twine operator+(const StringRef &LHS, const char *RHS) {
+inline Twine operator+(StringRef LHS, const char *RHS) {
   return Twine(LHS, RHS);
 }
 
        
    
    
More information about the llvm-commits
mailing list