[llvm] 5dbcbb6 - [ADT] Store integers by value in Twine (NFC) (#158409)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 13 07:50:42 PDT 2025
Author: Kazu Hirata
Date: 2025-09-13T07:50:37-07:00
New Revision: 5dbcbb65abc808b2909d693038fd7e461e282371
URL: https://github.com/llvm/llvm-project/commit/5dbcbb65abc808b2909d693038fd7e461e282371
DIFF: https://github.com/llvm/llvm-project/commit/5dbcbb65abc808b2909d693038fd7e461e282371.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/ADT/Twine.h
llvm/lib/Support/Twine.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index 4ed4898df5459..249fb0ad83808 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -150,11 +150,11 @@ class Twine {
char character;
unsigned int decUI;
int decI;
- const unsigned long *decUL;
- const long *decL;
- const unsigned long long *decULL;
- const long long *decLL;
- const uint64_t *uHex;
+ unsigned long decUL;
+ long decL;
+ unsigned long long decULL;
+ long long decLL;
+ uint64_t uHex;
};
/// LHS - The prefix in the concatenation, which may be uninitialized for
@@ -336,22 +336,18 @@ class Twine {
explicit Twine(int Val) : LHSKind(DecIKind) { LHS.decI = Val; }
/// Construct a twine to print \p Val as an unsigned decimal integer.
- explicit Twine(const unsigned long &Val) : LHSKind(DecULKind) {
- LHS.decUL = &Val;
- }
+ explicit Twine(unsigned long Val) : LHSKind(DecULKind) { LHS.decUL = Val; }
/// Construct a twine to print \p Val as a signed decimal integer.
- explicit Twine(const long &Val) : LHSKind(DecLKind) { LHS.decL = &Val; }
+ explicit Twine(long Val) : LHSKind(DecLKind) { LHS.decL = Val; }
/// Construct a twine to print \p Val as an unsigned decimal integer.
- explicit Twine(const unsigned long long &Val) : LHSKind(DecULLKind) {
- LHS.decULL = &Val;
+ explicit Twine(unsigned long long Val) : LHSKind(DecULLKind) {
+ LHS.decULL = Val;
}
/// Construct a twine to print \p Val as a signed decimal integer.
- explicit Twine(const long long &Val) : LHSKind(DecLLKind) {
- LHS.decLL = &Val;
- }
+ explicit Twine(long long Val) : LHSKind(DecLLKind) { LHS.decLL = Val; }
// FIXME: Unfortunately, to make sure this is as efficient as possible we
// need extra binary constructors from particular types. We can't rely on
@@ -389,9 +385,9 @@ class Twine {
/// @{
// Construct a twine to print \p Val as an unsigned hexadecimal integer.
- static Twine utohexstr(const uint64_t &Val) {
+ static Twine utohexstr(uint64_t Val) {
Child LHS, RHS;
- LHS.uHex = &Val;
+ LHS.uHex = Val;
RHS.twine = nullptr;
return Twine(LHS, UHexKind, RHS, EmptyKind);
}
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp
index d6b48166fb0f6..9d449161c298b 100644
--- a/llvm/lib/Support/Twine.cpp
+++ b/llvm/lib/Support/Twine.cpp
@@ -88,19 +88,19 @@ void Twine::printOneChild(raw_ostream &OS, Child Ptr, NodeKind Kind) const {
OS << Ptr.decI;
break;
case Twine::DecULKind:
- OS << *Ptr.decUL;
+ OS << Ptr.decUL;
break;
case Twine::DecLKind:
- OS << *Ptr.decL;
+ OS << Ptr.decL;
break;
case Twine::DecULLKind:
- OS << *Ptr.decULL;
+ OS << Ptr.decULL;
break;
case Twine::DecLLKind:
- OS << *Ptr.decLL;
+ OS << Ptr.decLL;
break;
case Twine::UHexKind:
- OS.write_hex(*Ptr.uHex);
+ OS.write_hex(Ptr.uHex);
break;
}
}
@@ -144,16 +144,16 @@ void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr, NodeKind Kind) const {
OS << "decI:\"" << Ptr.decI << "\"";
break;
case Twine::DecULKind:
- OS << "decUL:\"" << *Ptr.decUL << "\"";
+ OS << "decUL:\"" << Ptr.decUL << "\"";
break;
case Twine::DecLKind:
- OS << "decL:\"" << *Ptr.decL << "\"";
+ OS << "decL:\"" << Ptr.decL << "\"";
break;
case Twine::DecULLKind:
- OS << "decULL:\"" << *Ptr.decULL << "\"";
+ OS << "decULL:\"" << Ptr.decULL << "\"";
break;
case Twine::DecLLKind:
- OS << "decLL:\"" << *Ptr.decLL << "\"";
+ OS << "decLL:\"" << Ptr.decLL << "\"";
break;
case Twine::UHexKind:
OS << "uhex:\"" << Ptr.uHex << "\"";
More information about the llvm-commits
mailing list