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:
Azat Khuzhin 2022-01-24 23:04:48 +03:00
parent f12e4b6ef7
commit b9948155cd
3 changed files with 5 additions and 5 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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);