-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[TableGen] Use std::string::find (NFC) #139681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TableGen] Use std::string::find (NFC) #139681
Conversation
This patch partially reverts llvm#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.
@llvm/pr-subscribers-tablegen Author: Kazu Hirata (kazutakahirata) ChangesThis patch partially reverts #139661 for a better solution. Full diff: https://github.com/llvm/llvm-project/pull/139681.diff 1 Files Affected:
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();
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/17718 Here is the relevant piece of the build log for the reference
|
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.