Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.
This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.
This doesn't actually modify StringRef yet, I'll do that in a follow-up.
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index cfe48eb..2ac34bb 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -57,7 +57,7 @@
bool IsInstruction = false;
GenericEnum *Enum = nullptr;
- GenericField(StringRef Name) : Name(Name) {}
+ GenericField(StringRef Name) : Name(std::string(Name)) {}
};
struct SearchIndex {
@@ -114,13 +114,14 @@
else if (BitInit *BI = dyn_cast<BitInit>(I))
return BI->getValue() ? "true" : "false";
else if (CodeInit *CI = dyn_cast<CodeInit>(I))
- return CI->getValue();
+ return std::string(CI->getValue());
else if (Field.IsIntrinsic)
return "Intrinsic::" + getIntrinsic(I).EnumName;
else if (Field.IsInstruction)
return I->getAsString();
else if (Field.Enum)
- return Field.Enum->EntryMap[cast<DefInit>(I)->getDef()]->first;
+ return std::string(
+ Field.Enum->EntryMap[cast<DefInit>(I)->getDef()]->first);
PrintFatalError(Twine("invalid field type for field '") + Field.Name +
"', expected: string, bits, bit or code");
}
@@ -274,7 +275,7 @@
void SearchableTableEmitter::emitIfdef(StringRef Guard, raw_ostream &OS) {
OS << "#ifdef " << Guard << "\n";
- PreprocessorGuards.insert(Guard);
+ PreprocessorGuards.insert(std::string(Guard));
}
/// Emit a generic enum.
@@ -542,7 +543,7 @@
const std::vector<StringRef> &Key,
bool EarlyOut) {
auto Index = std::make_unique<SearchIndex>();
- Index->Name = Name;
+ Index->Name = std::string(Name);
Index->EarlyOut = EarlyOut;
for (const auto &FieldName : Key) {
@@ -648,8 +649,8 @@
ValueField = EnumRec->getValueAsString("ValueField");
auto Enum = std::make_unique<GenericEnum>();
- Enum->Name = EnumRec->getName();
- Enum->PreprocessorGuard = EnumRec->getName();
+ Enum->Name = std::string(EnumRec->getName());
+ Enum->PreprocessorGuard = std::string(EnumRec->getName());
StringRef FilterClass = EnumRec->getValueAsString("FilterClass");
Enum->Class = Records.getClass(FilterClass);
@@ -665,9 +666,9 @@
for (auto TableRec : Records.getAllDerivedDefinitions("GenericTable")) {
auto Table = std::make_unique<GenericTable>();
- Table->Name = TableRec->getName();
- Table->PreprocessorGuard = TableRec->getName();
- Table->CppTypeName = TableRec->getValueAsString("CppTypeName");
+ Table->Name = std::string(TableRec->getName());
+ Table->PreprocessorGuard = std::string(TableRec->getName());
+ Table->CppTypeName = std::string(TableRec->getValueAsString("CppTypeName"));
std::vector<StringRef> Fields = TableRec->getValueAsListOfStrings("Fields");
for (const auto &FieldName : Fields) {
@@ -746,10 +747,10 @@
auto Table = std::make_unique<GenericTable>();
Table->Name = (Twine(Class->getName()) + "sList").str();
Table->PreprocessorGuard = Class->getName().upper();
- Table->CppTypeName = Class->getName();
+ Table->CppTypeName = std::string(Class->getName());
for (const RecordVal &Field : Class->getValues()) {
- std::string FieldName = Field.getName();
+ std::string FieldName = std::string(Field.getName());
// Skip uninteresting fields: either special to us, or injected
// template parameters (if they contain a ':').