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-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 6cb4276..237b2bd 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -851,20 +851,20 @@
size_t Len = ContainerName.size();
if (Len > 1 && ContainerName.endswith(Style == NS_UpperCase ? "S" : "s")) {
- IteratorName = ContainerName.substr(0, Len - 1);
+ IteratorName = std::string(ContainerName.substr(0, Len - 1));
// E.g.: (auto thing : things)
if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName())
return IteratorName;
}
if (Len > 2 && ContainerName.endswith(Style == NS_UpperCase ? "S_" : "s_")) {
- IteratorName = ContainerName.substr(0, Len - 2);
+ IteratorName = std::string(ContainerName.substr(0, Len - 2));
// E.g.: (auto thing : things_)
if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName())
return IteratorName;
}
- return OldIndex->getName();
+ return std::string(OldIndex->getName());
}
/// Determines whether or not the name \a Symbol conflicts with
@@ -899,7 +899,7 @@
// of DeclContext::lookup()). Why is this?
// Finally, determine if the symbol was used in the loop or a child context.
- DeclFinderASTVisitor DeclFinder(Symbol, GeneratedDecls);
+ DeclFinderASTVisitor DeclFinder(std::string(Symbol), GeneratedDecls);
return DeclFinder.findUsages(SourceStmt);
}