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/clang/lib/Tooling/RefactoringCallbacks.cpp b/clang/lib/Tooling/RefactoringCallbacks.cpp
index 919b83b..e3fc91a 100644
--- a/clang/lib/Tooling/RefactoringCallbacks.cpp
+++ b/clang/lib/Tooling/RefactoringCallbacks.cpp
@@ -50,8 +50,8 @@
for (const auto &Callback : Refactoring.Callbacks) {
for (const auto &Replacement : Callback->getReplacements()) {
llvm::Error Err =
- Refactoring.FileToReplaces[Replacement.getFilePath()].add(
- Replacement);
+ Refactoring.FileToReplaces[std::string(Replacement.getFilePath())]
+ .add(Replacement);
if (Err) {
llvm::errs() << "Skipping replacement " << Replacement.toString()
<< " due to this error:\n"
@@ -83,7 +83,7 @@
}
ReplaceStmtWithText::ReplaceStmtWithText(StringRef FromId, StringRef ToText)
- : FromId(FromId), ToText(ToText) {}
+ : FromId(std::string(FromId)), ToText(std::string(ToText)) {}
void ReplaceStmtWithText::run(
const ast_matchers::MatchFinder::MatchResult &Result) {
@@ -101,7 +101,7 @@
}
ReplaceStmtWithStmt::ReplaceStmtWithStmt(StringRef FromId, StringRef ToId)
- : FromId(FromId), ToId(ToId) {}
+ : FromId(std::string(FromId)), ToId(std::string(ToId)) {}
void ReplaceStmtWithStmt::run(
const ast_matchers::MatchFinder::MatchResult &Result) {
@@ -121,7 +121,7 @@
ReplaceIfStmtWithItsBody::ReplaceIfStmtWithItsBody(StringRef Id,
bool PickTrueBranch)
- : Id(Id), PickTrueBranch(PickTrueBranch) {}
+ : Id(std::string(Id)), PickTrueBranch(PickTrueBranch) {}
void ReplaceIfStmtWithItsBody::run(
const ast_matchers::MatchFinder::MatchResult &Result) {
@@ -153,7 +153,7 @@
ReplaceNodeWithTemplate::ReplaceNodeWithTemplate(
llvm::StringRef FromId, std::vector<TemplateElement> Template)
- : FromId(FromId), Template(std::move(Template)) {}
+ : FromId(std::string(FromId)), Template(std::move(Template)) {}
llvm::Expected<std::unique_ptr<ReplaceNodeWithTemplate>>
ReplaceNodeWithTemplate::create(StringRef FromId, StringRef ToTemplate) {
@@ -172,8 +172,8 @@
ToTemplate.substr(Index),
llvm::inconvertibleErrorCode());
}
- std::string SourceNodeName =
- ToTemplate.substr(Index + 2, EndOfIdentifier - Index - 2);
+ std::string SourceNodeName = std::string(
+ ToTemplate.substr(Index + 2, EndOfIdentifier - Index - 2));
ParsedTemplate.push_back(
TemplateElement{TemplateElement::Identifier, SourceNodeName});
Index = EndOfIdentifier + 1;
@@ -185,9 +185,9 @@
}
} else {
size_t NextIndex = ToTemplate.find('$', Index + 1);
- ParsedTemplate.push_back(
- TemplateElement{TemplateElement::Literal,
- ToTemplate.substr(Index, NextIndex - Index)});
+ ParsedTemplate.push_back(TemplateElement{
+ TemplateElement::Literal,
+ std::string(ToTemplate.substr(Index, NextIndex - Index))});
Index = NextIndex;
}
}