[Lldb-commits] [lldb] r367384 - [StringList] Change LongestCommonPrefix API
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 30 20:26:10 PDT 2019
Author: jdevlieghere
Date: Tue Jul 30 20:26:10 2019
New Revision: 367384
URL: http://llvm.org/viewvc/llvm-project?rev=367384&view=rev
Log:
[StringList] Change LongestCommonPrefix API
When investigating a completion bug I got confused by the API.
LongestCommonPrefix finds the longest common prefix of the strings in
the string list. Instead of returning that string through an output
argument, just return it by value.
Modified:
lldb/trunk/include/lldb/Utility/StringList.h
lldb/trunk/source/Core/IOHandler.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Utility/StringList.cpp
lldb/trunk/unittests/Utility/StringListTest.cpp
Modified: lldb/trunk/include/lldb/Utility/StringList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StringList.h?rev=367384&r1=367383&r2=367384&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/StringList.h (original)
+++ lldb/trunk/include/lldb/Utility/StringList.h Tue Jul 30 20:26:10 2019
@@ -69,7 +69,7 @@ public:
void Clear();
- void LongestCommonPrefix(std::string &common_prefix);
+ std::string LongestCommonPrefix();
void InsertStringAtIndex(size_t idx, const std::string &str);
Modified: lldb/trunk/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=367384&r1=367383&r2=367384&view=diff
==============================================================================
--- lldb/trunk/source/Core/IOHandler.cpp (original)
+++ lldb/trunk/source/Core/IOHandler.cpp Tue Jul 30 20:26:10 2019
@@ -243,8 +243,7 @@ int IOHandlerDelegate::IOHandlerComplete
size_t num_matches = request.GetNumberOfMatches();
if (num_matches > 0) {
- std::string common_prefix;
- matches.LongestCommonPrefix(common_prefix);
+ std::string common_prefix = matches.LongestCommonPrefix();
const size_t partial_name_len = request.GetCursorArgumentPrefix().size();
// If we matched a unique single command, add a space... Only do this if
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=367384&r1=367383&r2=367384&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Jul 30 20:26:10 2019
@@ -1857,8 +1857,7 @@ int CommandInterpreter::HandleCompletion
// element 0, otherwise put an empty string in element 0.
std::string command_partial_str = request.GetCursorArgumentPrefix().str();
- std::string common_prefix;
- matches.LongestCommonPrefix(common_prefix);
+ std::string common_prefix = matches.LongestCommonPrefix();
const size_t partial_name_len = command_partial_str.size();
common_prefix.erase(0, partial_name_len);
Modified: lldb/trunk/source/Utility/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringList.cpp?rev=367384&r1=367383&r2=367384&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StringList.cpp (original)
+++ lldb/trunk/source/Utility/StringList.cpp Tue Jul 30 20:26:10 2019
@@ -100,10 +100,9 @@ void StringList::Join(const char *separa
void StringList::Clear() { m_strings.clear(); }
-void StringList::LongestCommonPrefix(std::string &common_prefix) {
- common_prefix.clear();
+std::string StringList::LongestCommonPrefix() {
if (m_strings.empty())
- return;
+ return {};
auto args = llvm::makeArrayRef(m_strings);
llvm::StringRef prefix = args.front();
@@ -115,7 +114,7 @@ void StringList::LongestCommonPrefix(std
}
prefix = prefix.take_front(count);
}
- common_prefix = prefix;
+ return prefix.str();
}
void StringList::InsertStringAtIndex(size_t idx, const char *str) {
Modified: lldb/trunk/unittests/Utility/StringListTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StringListTest.cpp?rev=367384&r1=367383&r2=367384&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/StringListTest.cpp (original)
+++ lldb/trunk/unittests/Utility/StringListTest.cpp Tue Jul 30 20:26:10 2019
@@ -214,8 +214,7 @@ TEST(StringListTest, SplitIntoLinesEmpty
TEST(StringListTest, LongestCommonPrefixEmpty) {
StringList s;
- std::string prefix = "this should be cleared";
- s.LongestCommonPrefix(prefix);
+ std::string prefix = s.LongestCommonPrefix();
EXPECT_EQ("", prefix);
}
@@ -226,8 +225,7 @@ TEST(StringListTest, LongestCommonPrefix
s.AppendString("foo");
s.AppendString("foozar");
- std::string prefix = "this should be cleared";
- s.LongestCommonPrefix(prefix);
+ std::string prefix = s.LongestCommonPrefix();
EXPECT_EQ("foo", prefix);
}
@@ -235,8 +233,7 @@ TEST(StringListTest, LongestCommonPrefix
StringList s;
s.AppendString("foo");
- std::string prefix = "this should be cleared";
- s.LongestCommonPrefix(prefix);
+ std::string prefix = s.LongestCommonPrefix();
EXPECT_EQ("foo", prefix);
}
@@ -245,8 +242,7 @@ TEST(StringListTest, LongestCommonPrefix
s.AppendString("foo");
s.AppendString("foo");
- std::string prefix = "this should be cleared";
- s.LongestCommonPrefix(prefix);
+ std::string prefix = s.LongestCommonPrefix();
EXPECT_EQ("foo", prefix);
}
@@ -257,8 +253,7 @@ TEST(StringListTest, LongestCommonPrefix
s.AppendString("2foo");
s.AppendString("3foozar");
- std::string prefix = "this should be cleared";
- s.LongestCommonPrefix(prefix);
+ std::string prefix = s.LongestCommonPrefix();
EXPECT_EQ("", prefix);
}
More information about the lldb-commits
mailing list