diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2019-07-31 03:26:10 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2019-07-31 03:26:10 +0000 |
commit | 175f0930907c56a80e0500cd201910c36222e788 (patch) | |
tree | dc3e71279bcd2a9f9e6c7d32e21916ecd04783e8 | |
parent | e825b834ecbd322db137ae8b69b6450282846ee8 (diff) | |
download | bcm5719-llvm-175f0930907c56a80e0500cd201910c36222e788.tar.gz bcm5719-llvm-175f0930907c56a80e0500cd201910c36222e788.zip |
[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.
llvm-svn: 367384
-rw-r--r-- | lldb/include/lldb/Utility/StringList.h | 2 | ||||
-rw-r--r-- | lldb/source/Core/IOHandler.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Utility/StringList.cpp | 7 | ||||
-rw-r--r-- | lldb/unittests/Utility/StringListTest.cpp | 15 |
5 files changed, 11 insertions, 19 deletions
diff --git a/lldb/include/lldb/Utility/StringList.h b/lldb/include/lldb/Utility/StringList.h index 68c1f87510f..22b5b2c3b09 100644 --- a/lldb/include/lldb/Utility/StringList.h +++ b/lldb/include/lldb/Utility/StringList.h @@ -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); diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 203b9e8af07..51cae59639f 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -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 diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 379251b0276..2bc41621af5 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -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); diff --git a/lldb/source/Utility/StringList.cpp b/lldb/source/Utility/StringList.cpp index fb0d9be8797..03249e00ccc 100644 --- a/lldb/source/Utility/StringList.cpp +++ b/lldb/source/Utility/StringList.cpp @@ -100,10 +100,9 @@ void StringList::Join(const char *separator, Stream &strm) { 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::string &common_prefix) { } prefix = prefix.take_front(count); } - common_prefix = prefix; + return prefix.str(); } void StringList::InsertStringAtIndex(size_t idx, const char *str) { diff --git a/lldb/unittests/Utility/StringListTest.cpp b/lldb/unittests/Utility/StringListTest.cpp index 7d62631bb8e..a0890800861 100644 --- a/lldb/unittests/Utility/StringListTest.cpp +++ b/lldb/unittests/Utility/StringListTest.cpp @@ -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, LongestCommonPrefixSingleElement) { 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, LongestCommonPrefixDuplicateElement) { 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, LongestCommonPrefixNoPrefix) { s.AppendString("2foo"); s.AppendString("3foozar"); - std::string prefix = "this should be cleared"; - s.LongestCommonPrefix(prefix); + std::string prefix = s.LongestCommonPrefix(); EXPECT_EQ("", prefix); } |