Skip to content

Commit 067e30d

Browse files
committed
[NFC][LLVM][ADT] Change a few const StringRef & arguments to value
Per LLVM Programmer's Manual, StringRef should always be passed by value. Enforcing this for a few ADT functions.
1 parent a55c4c8 commit 067e30d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/Hashing.h"
2222
#include "llvm/ADT/STLForwardCompat.h"
2323
#include "llvm/ADT/STLFunctionalExtras.h"
24+
#include "llvm/ADT/StringRef.h"
2425
#include "llvm/ADT/iterator.h"
2526
#include "llvm/ADT/iterator_range.h"
2627
#include "llvm/Config/abi-breaking.h"
@@ -2215,13 +2216,12 @@ inline void interleave(const Container &c, UnaryFunctor each_fn,
22152216
template <typename Container, typename UnaryFunctor, typename StreamT,
22162217
typename T = detail::ValueOfRange<Container>>
22172218
inline void interleave(const Container &c, StreamT &os, UnaryFunctor each_fn,
2218-
const StringRef &separator) {
2219+
StringRef separator) {
22192220
interleave(adl_begin(c), adl_end(c), each_fn, [&] { os << separator; });
22202221
}
22212222
template <typename Container, typename StreamT,
22222223
typename T = detail::ValueOfRange<Container>>
2223-
inline void interleave(const Container &c, StreamT &os,
2224-
const StringRef &separator) {
2224+
inline void interleave(const Container &c, StreamT &os, StringRef separator) {
22252225
interleave(
22262226
c, os, [&](const T &a) { os << a; }, separator);
22272227
}

llvm/include/llvm/ADT/Twine.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class Twine {
285285
}
286286

287287
/// Construct from a StringRef.
288-
/*implicit*/ Twine(const StringRef &Str) : LHSKind(PtrAndLengthKind) {
288+
/*implicit*/ Twine(StringRef Str) : LHSKind(PtrAndLengthKind) {
289289
LHS.ptrAndLength.ptr = Str.data();
290290
LHS.ptrAndLength.length = Str.size();
291291
assert(isValid() && "Invalid twine!");
@@ -352,7 +352,7 @@ class Twine {
352352
// right thing. Yet.
353353

354354
/// Construct as the concatenation of a C string and a StringRef.
355-
/*implicit*/ Twine(const char *LHS, const StringRef &RHS)
355+
/*implicit*/ Twine(const char *LHS, StringRef RHS)
356356
: LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
357357
this->LHS.cString = LHS;
358358
this->RHS.ptrAndLength.ptr = RHS.data();
@@ -361,7 +361,7 @@ class Twine {
361361
}
362362

363363
/// Construct as the concatenation of a StringRef and a C string.
364-
/*implicit*/ Twine(const StringRef &LHS, const char *RHS)
364+
/*implicit*/ Twine(StringRef LHS, const char *RHS)
365365
: LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
366366
this->LHS.ptrAndLength.ptr = LHS.data();
367367
this->LHS.ptrAndLength.length = LHS.size();
@@ -530,14 +530,14 @@ inline Twine operator+(const Twine &LHS, const Twine &RHS) {
530530
/// Additional overload to guarantee simplified codegen; this is equivalent to
531531
/// concat().
532532

533-
inline Twine operator+(const char *LHS, const StringRef &RHS) {
533+
inline Twine operator+(const char *LHS, StringRef RHS) {
534534
return Twine(LHS, RHS);
535535
}
536536

537537
/// Additional overload to guarantee simplified codegen; this is equivalent to
538538
/// concat().
539539

540-
inline Twine operator+(const StringRef &LHS, const char *RHS) {
540+
inline Twine operator+(StringRef LHS, const char *RHS) {
541541
return Twine(LHS, RHS);
542542
}
543543

0 commit comments

Comments
 (0)