mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Remove extra copying for completion words
Return Replxx::completions_t over Words array, that way we avoids one copying of std::string (although it breaks incapsulation).
This commit is contained in:
parent
f12e4b6ef7
commit
b9948155cd
@ -36,7 +36,7 @@ bool hasInputData()
|
||||
|
||||
}
|
||||
|
||||
LineReader::Suggest::Words LineReader::Suggest::getCompletions(const String & prefix, size_t prefix_length)
|
||||
replxx::Replxx::completions_t LineReader::Suggest::getCompletions(const String & prefix, size_t prefix_length)
|
||||
{
|
||||
std::string_view last_word;
|
||||
|
||||
@ -64,7 +64,7 @@ LineReader::Suggest::Words LineReader::Suggest::getCompletions(const String & pr
|
||||
return strncmp(s.data(), prefix_searched.data(), prefix_length) < 0;
|
||||
});
|
||||
|
||||
return Words(range.first, range.second);
|
||||
return replxx::Replxx::completions_t(range.first, range.second);
|
||||
}
|
||||
|
||||
void LineReader::Suggest::addWords(Words && new_words)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <replxx.hxx>
|
||||
|
||||
#include <base/types.h>
|
||||
|
||||
@ -15,7 +16,7 @@ public:
|
||||
using Words = std::vector<std::string>;
|
||||
|
||||
/// Get vector for the matched range of words if any.
|
||||
Words getCompletions(const String & prefix, size_t prefix_length);
|
||||
replxx::Replxx::completions_t getCompletions(const String & prefix, size_t prefix_length);
|
||||
void addWords(Words && new_words);
|
||||
|
||||
private:
|
||||
|
@ -179,8 +179,7 @@ ReplxxLineReader::ReplxxLineReader(
|
||||
|
||||
auto callback = [&suggest] (const String & context, size_t context_size)
|
||||
{
|
||||
auto words = suggest.getCompletions(context, context_size);
|
||||
return Replxx::completions_t(words.begin(), words.end());
|
||||
return suggest.getCompletions(context, context_size);
|
||||
};
|
||||
|
||||
rx.set_completion_callback(callback);
|
||||
|
Loading…
Reference in New Issue
Block a user