Skip to content

Commit 5dbcbb6

Browse files
[ADT] Store integers by value in Twine (NFC) (#158409)
This patch stores integers by value in Twine for simplicity. I don't think there is a good reason to store char, unsigned, and int by value and all the other integers by pointers.
1 parent 3f4eb81 commit 5dbcbb6

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

llvm/include/llvm/ADT/Twine.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class Twine {
150150
char character;
151151
unsigned int decUI;
152152
int decI;
153-
const unsigned long *decUL;
154-
const long *decL;
155-
const unsigned long long *decULL;
156-
const long long *decLL;
157-
const uint64_t *uHex;
153+
unsigned long decUL;
154+
long decL;
155+
unsigned long long decULL;
156+
long long decLL;
157+
uint64_t uHex;
158158
};
159159

160160
/// LHS - The prefix in the concatenation, which may be uninitialized for
@@ -336,22 +336,18 @@ class Twine {
336336
explicit Twine(int Val) : LHSKind(DecIKind) { LHS.decI = Val; }
337337

338338
/// Construct a twine to print \p Val as an unsigned decimal integer.
339-
explicit Twine(const unsigned long &Val) : LHSKind(DecULKind) {
340-
LHS.decUL = &Val;
341-
}
339+
explicit Twine(unsigned long Val) : LHSKind(DecULKind) { LHS.decUL = Val; }
342340

343341
/// Construct a twine to print \p Val as a signed decimal integer.
344-
explicit Twine(const long &Val) : LHSKind(DecLKind) { LHS.decL = &Val; }
342+
explicit Twine(long Val) : LHSKind(DecLKind) { LHS.decL = Val; }
345343

346344
/// Construct a twine to print \p Val as an unsigned decimal integer.
347-
explicit Twine(const unsigned long long &Val) : LHSKind(DecULLKind) {
348-
LHS.decULL = &Val;
345+
explicit Twine(unsigned long long Val) : LHSKind(DecULLKind) {
346+
LHS.decULL = Val;
349347
}
350348

351349
/// Construct a twine to print \p Val as a signed decimal integer.
352-
explicit Twine(const long long &Val) : LHSKind(DecLLKind) {
353-
LHS.decLL = &Val;
354-
}
350+
explicit Twine(long long Val) : LHSKind(DecLLKind) { LHS.decLL = Val; }
355351

356352
// FIXME: Unfortunately, to make sure this is as efficient as possible we
357353
// need extra binary constructors from particular types. We can't rely on
@@ -389,9 +385,9 @@ class Twine {
389385
/// @{
390386

391387
// Construct a twine to print \p Val as an unsigned hexadecimal integer.
392-
static Twine utohexstr(const uint64_t &Val) {
388+
static Twine utohexstr(uint64_t Val) {
393389
Child LHS, RHS;
394-
LHS.uHex = &Val;
390+
LHS.uHex = Val;
395391
RHS.twine = nullptr;
396392
return Twine(LHS, UHexKind, RHS, EmptyKind);
397393
}

llvm/lib/Support/Twine.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ void Twine::printOneChild(raw_ostream &OS, Child Ptr, NodeKind Kind) const {
8888
OS << Ptr.decI;
8989
break;
9090
case Twine::DecULKind:
91-
OS << *Ptr.decUL;
91+
OS << Ptr.decUL;
9292
break;
9393
case Twine::DecLKind:
94-
OS << *Ptr.decL;
94+
OS << Ptr.decL;
9595
break;
9696
case Twine::DecULLKind:
97-
OS << *Ptr.decULL;
97+
OS << Ptr.decULL;
9898
break;
9999
case Twine::DecLLKind:
100-
OS << *Ptr.decLL;
100+
OS << Ptr.decLL;
101101
break;
102102
case Twine::UHexKind:
103-
OS.write_hex(*Ptr.uHex);
103+
OS.write_hex(Ptr.uHex);
104104
break;
105105
}
106106
}
@@ -144,16 +144,16 @@ void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr, NodeKind Kind) const {
144144
OS << "decI:\"" << Ptr.decI << "\"";
145145
break;
146146
case Twine::DecULKind:
147-
OS << "decUL:\"" << *Ptr.decUL << "\"";
147+
OS << "decUL:\"" << Ptr.decUL << "\"";
148148
break;
149149
case Twine::DecLKind:
150-
OS << "decL:\"" << *Ptr.decL << "\"";
150+
OS << "decL:\"" << Ptr.decL << "\"";
151151
break;
152152
case Twine::DecULLKind:
153-
OS << "decULL:\"" << *Ptr.decULL << "\"";
153+
OS << "decULL:\"" << Ptr.decULL << "\"";
154154
break;
155155
case Twine::DecLLKind:
156-
OS << "decLL:\"" << *Ptr.decLL << "\"";
156+
OS << "decLL:\"" << Ptr.decLL << "\"";
157157
break;
158158
case Twine::UHexKind:
159159
OS << "uhex:\"" << Ptr.uHex << "\"";

0 commit comments

Comments
 (0)