[llvm] [TableGen] Use std::string::find (NFC) (PR #139681)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 13 00:27:39 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/139681.diff
1 Files Affected:
- (modified) llvm/lib/TableGen/Record.cpp (+4-4)
``````````diff
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 0d9fcb0e63dae..bc0ccfd64d155 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -1796,11 +1796,11 @@ 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 found;
+ std::string::size_type idx = 0;
while (true) {
- found = StringRef(Val).find(LHSs->getValue(), idx);
- if (found == StringRef::npos)
+ 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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/139681
More information about the llvm-commits
mailing list