[llvm] 298ace7 - [TableGen] Use std::string::find (NFC) (#139681)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 13 15:50:12 PDT 2025
Author: Kazu Hirata
Date: 2025-05-13T15:50:09-07:00
New Revision: 298ace7dff4f612e1d7dbf7bc18c32ee6c6c774b
URL: https://github.com/llvm/llvm-project/commit/298ace7dff4f612e1d7dbf7bc18c32ee6c6c774b
DIFF: https://github.com/llvm/llvm-project/commit/298ace7dff4f612e1d7dbf7bc18c32ee6c6c774b.diff
LOG: [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.
Added:
Modified:
llvm/lib/TableGen/Record.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 0d9fcb0e63dae..b01257fd71359 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -1796,14 +1796,13 @@ const Init *TernOpInit::Fold(const Record *CurRec) const {
if (LHSs && MHSs && RHSs) {
std::string Val = RHSs->getValue().str();
- StringRef::size_type found;
- StringRef::size_type idx = 0;
+ std::string::size_type Idx = 0;
while (true) {
- found = StringRef(Val).find(LHSs->getValue(), idx);
- if (found == StringRef::npos)
+ std::string::size_type Found = Val.find(LHSs->getValue(), Idx);
+ if (Found == std::string::npos)
break;
- Val.replace(found, LHSs->getValue().size(), MHSs->getValue().str());
- idx = found + MHSs->getValue().size();
+ Val.replace(Found, LHSs->getValue().size(), MHSs->getValue().str());
+ Idx = Found + MHSs->getValue().size();
}
return StringInit::get(RK, Val);
More information about the llvm-commits
mailing list