Skip to content

Commit d0deaa8

Browse files
committed
Do not serialize the input Twine more than once
1 parent 90eff5f commit d0deaa8

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

llvm/include/llvm/TableGen/CodeGenHelpers.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace llvm {
2323
class IfDefEmitter {
2424
public:
2525
IfDefEmitter(raw_ostream &OS, const Twine &Name) : Name(Name.str()), OS(OS) {
26-
OS << "#ifdef " << Name << "\n"
27-
<< "#undef " << Name << "\n\n";
26+
OS << "#ifdef " << this->Name << "\n"
27+
<< "#undef " << this->Name << "\n\n";
2828
}
2929
~IfDefEmitter() { OS << "\n#endif // " << Name << "\n\n"; }
3030

@@ -38,8 +38,8 @@ class IncludeGuardEmitter {
3838
public:
3939
IncludeGuardEmitter(raw_ostream &OS, const Twine &Name)
4040
: Name(Name.str()), OS(OS) {
41-
OS << "#ifndef " << Name << "\n"
42-
<< "#define " << Name << "\n\n";
41+
OS << "#ifndef " << this->Name << "\n"
42+
<< "#define " << this->Name << "\n\n";
4343
}
4444
~IncludeGuardEmitter() { OS << "\n#endif // " << Name << "\n"; }
4545

@@ -53,10 +53,10 @@ class IncludeGuardEmitter {
5353
// namespace scope.
5454
class NamespaceEmitter {
5555
public:
56-
NamespaceEmitter(raw_ostream &OS, const Twine &NameUntrimmed)
57-
: Name(trim(NameUntrimmed)), OS(OS) {
58-
if (!Name.empty())
59-
OS << "namespace " << Name << " {\n";
56+
NamespaceEmitter(raw_ostream &OS, const Twine &Name)
57+
: Name(trim(Name.str())), OS(OS) {
58+
if (!this->Name.empty())
59+
OS << "namespace " << this->Name << " {\n";
6060
}
6161

6262
~NamespaceEmitter() { close(); }
@@ -76,8 +76,7 @@ class NamespaceEmitter {
7676
// }
7777
//
7878
// and cannot use "namespace ::mlir::toy".
79-
static std::string trim(const Twine &NameUntrimmed) {
80-
std::string Name = NameUntrimmed.str();
79+
static std::string trim(std::string Name) {
8180
StringRef StrRef = Name;
8281
StrRef.consume_front("::");
8382
return StrRef.str();

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4938,7 +4938,7 @@ static void emitOpDefShard(const RecordKeeper &records,
49384938
ArrayRef<const Record *> defs,
49394939
const Dialect &dialect, unsigned shardIndex,
49404940
unsigned shardCount, raw_ostream &os) {
4941-
IfDefEmitter scope(os, Twine("GET_OP_DEFS_") + Twine(shardIndex));
4941+
IfDefEmitter scope(os, "GET_OP_DEFS_" + Twine(shardIndex));
49424942

49434943
// Emit the op registration hook in the first shard.
49444944
const char *const opRegistrationHook =

0 commit comments

Comments
 (0)