Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

std::string::find accepts anything that can be converted to
std::string_view starting in C++17. Since StringRef can be converted
to std::string_view, we do not need to create a temporary instance of
std::string here.

std::string::find accepts anything that can be converted to
std::string_view starting in C++17.  Since StringRef can be converted
to std::string_view, we do not need to create a temporary instance of
std::string here.
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-lldb

Author: Kazu Hirata (kazutakahirata)

Changes

std::string::find accepts anything that can be converted to
std::string_view starting in C++17. Since StringRef can be converted
to std::string_view, we do not need to create a temporary instance of
std::string here.


Full diff: https://github.com/llvm/llvm-project/pull/139679.diff

1 Files Affected:

  • (modified) lldb/source/Interpreter/Options.cpp (+1-1)
diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp
index fdadba62987d3..4cf68db466158 100644
--- a/lldb/source/Interpreter/Options.cpp
+++ b/lldb/source/Interpreter/Options.cpp
@@ -1076,7 +1076,7 @@ llvm::Expected<Args> Options::ParseAlias(const Args &args,
 
     if (!input_line.empty()) {
       llvm::StringRef tmp_arg = args_copy[idx].ref();
-      size_t pos = input_line.find(std::string(tmp_arg));
+      size_t pos = input_line.find(tmp_arg);
       if (pos != std::string::npos)
         input_line.erase(pos, tmp_arg.size());
     }

@kazutakahirata kazutakahirata changed the title [lldb] Use std:::string::find with a std::string_view (NFC) [lldb] Use std:::string::find with std::string_view (NFC) May 13, 2025
@kazutakahirata kazutakahirata merged commit cc2bedd into llvm:main May 13, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_StringRef_find_lldb branch May 13, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants