[llvm] Use StringRef::{starts_with,find} (NFC) (#139661)

Calling find/contains in the StringRef domain allows us to avoid
creating temporary instances of std::string.
This commit is contained in:
Kazu Hirata
2025-05-12 23:24:07 -07:00
committed by GitHub
parent 294eb7670f
commit c95745f2db
2 changed files with 5 additions and 5 deletions

View File

@@ -780,7 +780,7 @@ llvm::Error DwarfTransformer::verify(StringRef GsymPath,
const auto &dii = DwarfInlineInfos.getFrame(Idx);
gsymFilename = LR->getSourceFile(Idx);
// Verify function name
if (dii.FunctionName.find(gii.Name.str()) != 0)
if (!StringRef(dii.FunctionName).starts_with(gii.Name))
Out << "error: address " << HEX64(Addr) << " DWARF function \""
<< dii.FunctionName.c_str()
<< "\" doesn't match GSYM function \"" << gii.Name << "\"\n";

View File

@@ -1796,11 +1796,11 @@ const Init *TernOpInit::Fold(const Record *CurRec) const {
if (LHSs && MHSs && RHSs) {
std::string Val = RHSs->getValue().str();
std::string::size_type found;
std::string::size_type idx = 0;
StringRef::size_type found;
StringRef::size_type idx = 0;
while (true) {
found = Val.find(LHSs->getValue().str(), idx);
if (found == std::string::npos)
found = StringRef(Val).find(LHSs->getValue(), idx);
if (found == StringRef::npos)
break;
Val.replace(found, LHSs->getValue().size(), MHSs->getValue().str());
idx = found + MHSs->getValue().size();