diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 88ed99a5..a7175d7e 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -95,10 +95,10 @@ void BufferManager::set_last_used_buffer(Buffer& buffer) m_buffers.emplace(m_buffers.begin(), &buffer); } -CandidateList BufferManager::complete_buffer_name(const String& prefix, +CandidateList BufferManager::complete_buffer_name(StringView prefix, ByteCount cursor_pos) { - String real_prefix = prefix.substr(0, cursor_pos); + auto real_prefix = prefix.substr(0, cursor_pos); const bool include_dirs = contains(real_prefix, '/'); CandidateList result; CandidateList subsequence_result; diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index 97124a2c..287ef672 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -33,7 +33,7 @@ public: Buffer& get_buffer(const String& name); void set_last_used_buffer(Buffer& buffer); - CandidateList complete_buffer_name(const String& prefix, + CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos = -1); private: diff --git a/src/client_manager.cc b/src/client_manager.cc index 12043456..6e3fd638 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -170,10 +170,10 @@ void ClientManager::redraw_clients() const client->redraw_ifn(); } -CandidateList ClientManager::complete_client_name(const String& prefix, +CandidateList ClientManager::complete_client_name(StringView prefix, ByteCount cursor_pos) const { - String real_prefix = prefix.substr(0, cursor_pos); + auto real_prefix = prefix.substr(0, cursor_pos); CandidateList result; CandidateList subsequence_result; for (auto& client : m_clients) diff --git a/src/client_manager.hh b/src/client_manager.hh index b25fe525..d3334486 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -39,7 +39,7 @@ public: bool validate_client_name(const String& name) const; void remove_client(Client& client); - CandidateList complete_client_name(const String& name, + CandidateList complete_client_name(StringView name, ByteCount cursor_pos = -1) const; private: diff --git a/src/color_registry.cc b/src/color_registry.cc index 0820409f..4867234d 100644 --- a/src/color_registry.cc +++ b/src/color_registry.cc @@ -36,11 +36,11 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc, it->second : parse_color_pair(colordesc); } -CandidateList ColorRegistry::complete_alias_name(const String& prefix, +CandidateList ColorRegistry::complete_alias_name(StringView prefix, ByteCount cursor_pos) const { CandidateList res; - String real_prefix = prefix.substr(0, cursor_pos); + auto real_prefix = prefix.substr(0, cursor_pos); for (auto& alias : m_aliases) { if (prefix_match(alias.first, real_prefix)) diff --git a/src/color_registry.hh b/src/color_registry.hh index 3eff6fab..24fcb5eb 100644 --- a/src/color_registry.hh +++ b/src/color_registry.hh @@ -19,7 +19,7 @@ public: void register_alias(const String& name, const String& colordesc, bool override = false); - CandidateList complete_alias_name(const String& prefix, + CandidateList complete_alias_name(StringView prefix, ByteCount cursor_pos) const; private: std::unordered_map m_aliases; diff --git a/src/commands.cc b/src/commands.cc index f5ed63ff..53b4fa67 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -495,7 +495,7 @@ HookManager& get_hook_manager(const String& scope, Context& context) throw runtime_error("error: no such hook container " + scope); } -CandidateList complete_scope(const String& prefix) +CandidateList complete_scope(StringView prefix) { CandidateList res; for (auto scope : { "global", "buffer", "window" }) diff --git a/src/completion.cc b/src/completion.cc index a3e99ce4..9fc3ed78 100644 --- a/src/completion.cc +++ b/src/completion.cc @@ -6,7 +6,7 @@ namespace Kakoune { Completions shell_complete(const Context& context, CompletionFlags flags, - const String& prefix, ByteCount cursor_pos) + StringView prefix, ByteCount cursor_pos) { ByteCount word_start = 0; ByteCount word_end = 0; diff --git a/src/completion.hh b/src/completion.hh index fc58d1c4..6cda2e6c 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -5,13 +5,13 @@ #include #include "units.hh" +#include "string.hh" namespace Kakoune { class Context; -class String; using CandidateList = std::vector; struct Completions @@ -36,16 +36,16 @@ enum class CompletionFlags Fast }; using Completer = std::function; + StringView, ByteCount)>; inline Completions complete_nothing(const Context& context, CompletionFlags, - const String&, ByteCount cursor_pos) + StringView, ByteCount cursor_pos) { return Completions(cursor_pos, cursor_pos); } Completions shell_complete(const Context& context, CompletionFlags, - const String&, ByteCount cursor_pos); + StringView, ByteCount cursor_pos); } #endif // completion_hh_INCLUDED diff --git a/src/file.cc b/src/file.cc index c295217f..c3df5f54 100644 --- a/src/file.cc +++ b/src/file.cc @@ -311,7 +311,7 @@ std::vector list_files(const String& prefix, return result.empty() ? subseq_result : result; } -std::vector complete_filename(const String& prefix, +std::vector complete_filename(StringView prefix, const Regex& ignored_regex, ByteCount cursor_pos) { @@ -346,7 +346,7 @@ std::vector complete_filename(const String& prefix, return res; } -std::vector complete_command(const String& prefix, ByteCount cursor_pos) +std::vector complete_command(StringView prefix, ByteCount cursor_pos) { String real_prefix = parse_filename(prefix.substr(0, cursor_pos)); String dirname; diff --git a/src/file.hh b/src/file.hh index 818d6de1..91e27d9d 100644 --- a/src/file.hh +++ b/src/file.hh @@ -35,12 +35,12 @@ String find_file(const String& filename, memoryview paths); time_t get_fs_timestamp(const String& filename); -std::vector complete_filename(const String& prefix, +std::vector complete_filename(StringView prefix, const Regex& ignore_regex, ByteCount cursor_pos = -1); -std::vector complete_command(const String& prefix, - ByteCount cursor_pos = -1); +std::vector complete_command(StringView prefix, + ByteCount cursor_pos = -1); } #endif // file_hh_INCLUDED diff --git a/src/function_group.hh b/src/function_group.hh index a3371c53..3bac5159 100644 --- a/src/function_group.hh +++ b/src/function_group.hh @@ -54,12 +54,12 @@ public: return *group; } - CandidateList complete_id(const String& prefix, ByteCount cursor_pos) const + CandidateList complete_id(StringView prefix, ByteCount cursor_pos) const { return m_functions.complete_id(prefix, cursor_pos); } - CandidateList complete_group_id(const String& prefix, ByteCount cursor_pos) const + CandidateList complete_group_id(StringView prefix, ByteCount cursor_pos) const { return m_functions.complete_id_if( prefix, cursor_pos, [](const FunctionAndId& func) { diff --git a/src/function_registry.hh b/src/function_registry.hh index d62f9ae8..2dbf1f02 100644 --- a/src/function_registry.hh +++ b/src/function_registry.hh @@ -32,7 +32,7 @@ public: return it->second; } - CandidateList complete_name(const String& prefix, ByteCount cursor_pos) + CandidateList complete_name(StringView prefix, ByteCount cursor_pos) { return m_functions.complete_id(prefix, cursor_pos); } diff --git a/src/id_map.hh b/src/id_map.hh index 32462fa5..4ba91fe3 100644 --- a/src/id_map.hh +++ b/src/id_map.hh @@ -67,11 +67,11 @@ public: } template - CandidateList complete_id_if(const String& prefix, + CandidateList complete_id_if(StringView prefix, ByteCount cursor_pos, Condition condition) const { - String real_prefix = prefix.substr(0, cursor_pos); + auto real_prefix = prefix.substr(0, cursor_pos); CandidateList result; for (auto& value : m_content) { @@ -84,7 +84,7 @@ public: return result; } - CandidateList complete_id(const String& prefix, + CandidateList complete_id(StringView prefix, ByteCount cursor_pos) const { return complete_id_if( diff --git a/src/option_manager.cc b/src/option_manager.cc index ca9c145b..2bd9fd0c 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -85,14 +85,14 @@ CandidateList OptionManager::get_matching_names(MatchingFunc func) return result; } -CandidateList OptionManager::complete_option_name(const String& prefix, +CandidateList OptionManager::complete_option_name(StringView prefix, ByteCount cursor_pos) { using namespace std::placeholders; - String real_prefix = prefix.substr(0, cursor_pos); - auto result = get_matching_names(std::bind(prefix_match, _1, std::ref(real_prefix))); + auto real_prefix = prefix.substr(0, cursor_pos); + auto result = get_matching_names(std::bind(prefix_match, _1, real_prefix)); if (result.empty()) - result = get_matching_names(std::bind(subsequence_match, _1, std::ref(real_prefix))); + result = get_matching_names(std::bind(subsequence_match, _1, real_prefix)); return result; } diff --git a/src/option_manager.hh b/src/option_manager.hh index 6ceaac4c..32382b68 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -89,7 +89,7 @@ public: const Option& operator[] (const String& name) const; Option& get_local_option(const String& name); - CandidateList complete_option_name(const String& prefix, + CandidateList complete_option_name(StringView prefix, ByteCount cursor_pos); using OptionList = std::vector;