Skip to content

Commit 298ace7

Browse files
[TableGen] Use std::string::find (NFC) (#139681)
This patch partially reverts #139661 for a better solution. Specifically, we can take advantage of the fact that std::string::find accepts anything that can be converted to std::string_view, including StringRef, starting with C++17. This way, we do not need to cast Val to StringRef or LHSs->getValue() to std::string.
1 parent cc2bedd commit 298ace7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

llvm/lib/TableGen/Record.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,14 +1796,13 @@ const Init *TernOpInit::Fold(const Record *CurRec) const {
17961796
if (LHSs && MHSs && RHSs) {
17971797
std::string Val = RHSs->getValue().str();
17981798

1799-
StringRef::size_type found;
1800-
StringRef::size_type idx = 0;
1799+
std::string::size_type Idx = 0;
18011800
while (true) {
1802-
found = StringRef(Val).find(LHSs->getValue(), idx);
1803-
if (found == StringRef::npos)
1801+
std::string::size_type Found = Val.find(LHSs->getValue(), Idx);
1802+
if (Found == std::string::npos)
18041803
break;
1805-
Val.replace(found, LHSs->getValue().size(), MHSs->getValue().str());
1806-
idx = found + MHSs->getValue().size();
1804+
Val.replace(Found, LHSs->getValue().size(), MHSs->getValue().str());
1805+
Idx = Found + MHSs->getValue().size();
18071806
}
18081807

18091808
return StringInit::get(RK, Val);

0 commit comments

Comments
 (0)