diff --git a/src/memoryview.hh b/src/array_view.hh similarity index 69% rename from src/memoryview.hh rename to src/array_view.hh index 5f33b1fa..6a807c2c 100644 --- a/src/memoryview.hh +++ b/src/array_view.hh @@ -1,5 +1,5 @@ -#ifndef memoryview_hh_INCLUDED -#define memoryview_hh_INCLUDED +#ifndef array_view_hh_INCLUDED +#define array_view_hh_INCLUDED #include #include @@ -7,34 +7,34 @@ namespace Kakoune { -// A memoryview provides a typed, non owning view of a memory +// An ArrayView provides a typed, non owning view of a memory // range with an interface similar to std::vector. template -class memoryview +class ArrayView { public: using size_t = std::size_t; - memoryview() + ArrayView() : m_pointer(nullptr), m_size(0) {} - memoryview(const T& oneval) + ArrayView(const T& oneval) : m_pointer(&oneval), m_size(1) {} - memoryview(const T* pointer, size_t size) + ArrayView(const T* pointer, size_t size) : m_pointer(pointer), m_size(size) {} - memoryview(const T* begin, const T* end) + ArrayView(const T* begin, const T* end) : m_pointer(begin), m_size(end - begin) {} template - memoryview(const Iterator& begin, const Iterator& end) + ArrayView(const Iterator& begin, const Iterator& end) : m_pointer(&(*begin)), m_size(end - begin) {} - memoryview(const std::vector& v) + ArrayView(const std::vector& v) : m_pointer(&v[0]), m_size(v.size()) {} - memoryview(const std::initializer_list& v) + ArrayView(const std::initializer_list& v) : m_pointer(v.begin()), m_size(v.size()) {} const T* pointer() const { return m_pointer; } @@ -53,9 +53,9 @@ public: bool empty() const { return m_size == 0; } - memoryview subrange(size_t first, size_t count) const + ArrayView subrange(size_t first, size_t count) const { - return memoryview(m_pointer + first, count); + return ArrayView(m_pointer + first, count); } private: @@ -65,4 +65,4 @@ private: } -#endif // memoryview_hh_INCLUDED +#endif // array_view_hh_INCLUDED diff --git a/src/buffer.hh b/src/buffer.hh index ebb3eed7..609a030d 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -160,7 +160,7 @@ public: ByteCoord end; bool at_end; }; - memoryview changes_since(size_t timestamp) const; + ArrayView changes_since(size_t timestamp) const; String debug_description() const; private: diff --git a/src/buffer.inl.hh b/src/buffer.inl.hh index 7b09f1a4..fbd04d4a 100644 --- a/src/buffer.inl.hh +++ b/src/buffer.inl.hh @@ -92,7 +92,7 @@ inline size_t Buffer::timestamp() const return m_changes.size(); } -inline memoryview Buffer::changes_since(size_t timestamp) const +inline ArrayView Buffer::changes_since(size_t timestamp) const { return { m_changes.data() + timestamp, m_changes.data() + m_changes.size() }; diff --git a/src/command_manager.cc b/src/command_manager.cc index 390b3e99..32c06199 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -268,11 +268,11 @@ TokenList parse(StringView line) } String eval_token(const Token& token, Context& context, - memoryview shell_params, + ArrayView shell_params, const EnvVarMap& env_vars); String eval(StringView str, Context& context, - memoryview shell_params, + ArrayView shell_params, const EnvVarMap& env_vars) { String res; @@ -301,7 +301,7 @@ String eval(StringView str, Context& context, } String eval_token(const Token& token, Context& context, - memoryview shell_params, + ArrayView shell_params, const EnvVarMap& env_vars) { auto& content = token.content(); @@ -354,7 +354,7 @@ void CommandManager::execute_single_command(CommandParameters params, if (params.empty()) return; - memoryview param_view(params.begin()+1, params.end()); + ArrayView param_view(params.begin()+1, params.end()); auto command_it = find_command(context, params[0]); if (command_it == m_commands.end()) throw command_not_found(params[0]); @@ -394,7 +394,7 @@ static CharCoord find_coord(StringView str, ByteCount offset) void CommandManager::execute(StringView command_line, Context& context, - memoryview shell_params, + ArrayView shell_params, const EnvVarMap& env_vars) { TokenList tokens = parse(command_line); diff --git a/src/command_manager.hh b/src/command_manager.hh index 90b583f9..f6118781 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -4,7 +4,7 @@ #include "coord.hh" #include "completion.hh" #include "flags.hh" -#include "memoryview.hh" +#include "array_view.hh" #include "shell_manager.hh" #include "parameters_parser.hh" #include "string.hh" @@ -18,7 +18,7 @@ namespace Kakoune { class Context; -using CommandParameters = memoryview; +using CommandParameters = ArrayView; using Command = std::function; using CommandCompleter = std::function; - using ArgumentCompleterList = memoryview; + using ArgumentCompleterList = ArrayView; PerArgumentCommandCompleter(ArgumentCompleterList completers) : m_completers(completers.begin(), completers.end()) {} @@ -59,7 +59,7 @@ class CommandManager : public Singleton { public: void execute(StringView command_line, Context& context, - memoryview shell_params = {}, + ArrayView shell_params = {}, const EnvVarMap& env_vars = EnvVarMap{}); Completions complete(const Context& context, CompletionFlags flags, diff --git a/src/commands.cc b/src/commands.cc index 192c93fd..f549bd0c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1185,7 +1185,7 @@ const CommandDesc prompt_cmd = { { if (event != PromptEvent::Validate) return; - RegisterManager::instance()[reg] = memoryview(str); + RegisterManager::instance()[reg] = ArrayView(str); CommandManager::instance().execute(command, context); }); @@ -1361,7 +1361,7 @@ const CommandDesc set_register_cmd = { CommandCompleter{}, [](const ParametersParser& parser, Context& context) { - RegisterManager::instance()[parser[0]] = memoryview(parser[1]); + RegisterManager::instance()[parser[0]] = ArrayView(parser[1]); } }; @@ -1385,7 +1385,7 @@ public: RegisterRestorer(char name, const Context& context) : m_name(name) { - memoryview save = RegisterManager::instance()[name].values(context); + ArrayView save = RegisterManager::instance()[name].values(context); m_save = std::vector(save.begin(), save.end()); } @@ -1399,7 +1399,7 @@ private: } -void exec_keys(memoryview keys, Context& context) +void exec_keys(ArrayView keys, Context& context) { RegisterRestorer quote('"', context); RegisterRestorer slash('/', context); diff --git a/src/commands.hh b/src/commands.hh index e1f8f7e8..0923dc40 100644 --- a/src/commands.hh +++ b/src/commands.hh @@ -2,7 +2,7 @@ #define commands_hh_INCLUDED #include "keys.hh" -#include "memoryview.hh" +#include "array_view.hh" namespace Kakoune { @@ -10,7 +10,7 @@ namespace Kakoune class Context; void register_commands(); -void exec_keys(memoryview keys, Context& context); +void exec_keys(ArrayView keys, Context& context); } diff --git a/src/file.cc b/src/file.cc index 0012d256..96026300 100644 --- a/src/file.cc +++ b/src/file.cc @@ -230,7 +230,7 @@ void write_buffer_to_backup_file(Buffer& buffer) } } -String find_file(StringView filename, memoryview paths) +String find_file(StringView filename, ArrayView paths) { struct stat buf; if (filename.length() > 1 and filename[0] == '/') diff --git a/src/file.hh b/src/file.hh index c8caaf75..a8d2dc5c 100644 --- a/src/file.hh +++ b/src/file.hh @@ -22,7 +22,7 @@ struct file_not_found : file_access_error }; class Buffer; -template class memoryview; +template class ArrayView; class String; class StringView; @@ -42,7 +42,7 @@ void write_buffer_to_file(Buffer& buffer, StringView filename); void write_buffer_to_fd(Buffer& buffer, int fd); void write_buffer_to_backup_file(Buffer& buffer); -String find_file(StringView filename, memoryview paths); +String find_file(StringView filename, ArrayView paths); time_t get_fs_timestamp(StringView filename); diff --git a/src/highlighter.hh b/src/highlighter.hh index ae8ea0bd..028d4b2c 100644 --- a/src/highlighter.hh +++ b/src/highlighter.hh @@ -5,7 +5,7 @@ #include "completion.hh" #include "exception.hh" #include "id_map.hh" -#include "memoryview.hh" +#include "array_view.hh" #include "string.hh" #include "utils.hh" @@ -64,7 +64,7 @@ std::unique_ptr> make_simple_highlighter(T func) return make_unique>(std::move(func)); } -using HighlighterParameters = memoryview; +using HighlighterParameters = ArrayView; using HighlighterFactory = std::function; struct HighlighterRegistry : IdMap, diff --git a/src/highlighters.cc b/src/highlighters.cc index cbda7ea8..ed8e58b8 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -733,7 +733,7 @@ void find_matches(const Buffer& buffer, RegexMatchList& matches, const Regex& re } } -void update_matches(const Buffer& buffer, memoryview modifs, +void update_matches(const Buffer& buffer, ArrayView modifs, RegexMatchList& matches, const Regex& regex) { const size_t buf_timestamp = buffer.timestamp(); @@ -857,7 +857,7 @@ struct RegionDesc } void update_matches(const Buffer& buffer, - memoryview modifs, + ArrayView modifs, RegionMatches& matches) const { Kakoune::update_matches(buffer, modifs, matches.begin_matches, m_begin); diff --git a/src/input_handler.cc b/src/input_handler.cc index a57d65b1..2a5a1c82 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -340,7 +340,7 @@ private: class Menu : public InputMode { public: - Menu(InputHandler& input_handler, memoryview choices, + Menu(InputHandler& input_handler, ArrayView choices, MenuCallback callback) : InputMode(input_handler), m_callback(callback), m_choices(choices.begin(), choices.end()), @@ -458,7 +458,7 @@ private: LineEditor m_filter_editor; }; -String common_prefix(memoryview strings) +String common_prefix(ArrayView strings) { String res; if (strings.empty()) @@ -925,7 +925,7 @@ private: selections.sort_and_merge_overlapping(); } - void insert(memoryview strings) + void insert(ArrayView strings) { context().selections().insert(strings, InsertMode::InsertCursor); } @@ -1093,7 +1093,7 @@ void InputHandler::set_prompt_face(Face prompt_face) prompt->set_prompt_face(prompt_face); } -void InputHandler::menu(memoryview choices, +void InputHandler::menu(ArrayView choices, MenuCallback callback) { change_input_mode(new InputModes::Menu(*this, choices, callback)); @@ -1150,7 +1150,7 @@ bool InputHandler::is_recording() const void InputHandler::stop_recording() { kak_assert(m_recording_reg != 0); - RegisterManager::instance()[m_recording_reg] = memoryview(m_recorded_keys); + RegisterManager::instance()[m_recording_reg] = ArrayView(m_recorded_keys); m_recording_reg = 0; } diff --git a/src/input_handler.hh b/src/input_handler.hh index f65d4978..637e2271 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -61,7 +61,7 @@ public: // abort or validation with corresponding MenuEvent value // returns to normal mode after validation if callback does // not change the mode itself - void menu(memoryview choices, MenuCallback callback); + void menu(ArrayView choices, MenuCallback callback); // execute callback on next keypress and returns to normal mode // if callback does not change the mode itself diff --git a/src/keymap_manager.cc b/src/keymap_manager.cc index 668af430..4598c889 100644 --- a/src/keymap_manager.cc +++ b/src/keymap_manager.cc @@ -1,6 +1,6 @@ #include "keymap_manager.hh" -#include "memoryview.hh" +#include "array_view.hh" #include "assert.hh" namespace Kakoune @@ -23,7 +23,7 @@ bool KeymapManager::is_mapped(Key key, KeymapMode mode) const (m_parent and m_parent->is_mapped(key, mode)); } -memoryview KeymapManager::get_mapping(Key key, KeymapMode mode) const +ArrayView KeymapManager::get_mapping(Key key, KeymapMode mode) const { auto it = m_mapping.find({key, mode}); if (it != m_mapping.end()) diff --git a/src/keymap_manager.hh b/src/keymap_manager.hh index 1f5cb867..8387e1ef 100644 --- a/src/keymap_manager.hh +++ b/src/keymap_manager.hh @@ -22,7 +22,7 @@ enum class KeymapMode : int User, }; -template class memoryview; +template class ArrayView; class KeymapManager { @@ -34,7 +34,7 @@ public: void unmap_key(Key key, KeymapMode mode); bool is_mapped(Key key, KeymapMode mode) const; - memoryview get_mapping(Key key, KeymapMode mode) const; + ArrayView get_mapping(Key key, KeymapMode mode) const; private: KeymapManager() : m_parent(nullptr) {} diff --git a/src/main.cc b/src/main.cc index 6aa35004..64001537 100644 --- a/src/main.cc +++ b/src/main.cc @@ -311,7 +311,7 @@ int run_client(StringView session, StringView init_command) } int run_server(StringView session, StringView init_command, - bool ignore_kakrc, bool daemon, memoryview files) + bool ignore_kakrc, bool daemon, ArrayView files) { static bool terminate = false; if (daemon) @@ -412,7 +412,7 @@ int run_server(StringView session, StringView init_command, return 0; } -int run_filter(StringView keystr, memoryview files, bool quiet) +int run_filter(StringView keystr, ArrayView files, bool quiet) { StringRegistry string_registry; GlobalScope global_scope; diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 3b4d5b09..c69e101d 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -540,7 +540,7 @@ void NCursesUI::draw_menu() m_dirty = true; } -void NCursesUI::menu_show(memoryview items, +void NCursesUI::menu_show(ArrayView items, CharCoord anchor, Face fg, Face bg, MenuStyle style) { diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index b5f9b162..dde7a59f 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -27,7 +27,7 @@ public: bool is_key_available() override; Key get_key() override; - void menu_show(memoryview items, + void menu_show(ArrayView items, CharCoord anchor, Face fg, Face bg, MenuStyle style) override; void menu_select(int selected) override; diff --git a/src/normal.cc b/src/normal.cc index 35eb4db3..9ed62ba7 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1049,7 +1049,7 @@ void replay_macro(Context& context, NormalParams params) if (running_macros[idx]) throw runtime_error("recursive macros call detected"); - memoryview reg_val = RegisterManager::instance()[name].values(context); + ArrayView reg_val = RegisterManager::instance()[name].values(context); if (not reg_val.empty()) { running_macros[idx] = true; diff --git a/src/option_types.hh b/src/option_types.hh index a564fbe1..f1eb156c 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -5,7 +5,7 @@ #include "string.hh" #include "units.hh" #include "coord.hh" -#include "memoryview.hh" +#include "array_view.hh" #include "unordered_map.hh" #include @@ -109,7 +109,7 @@ struct TupleOptionDetail tuple_separator + escape(option_to_string(std::get(opt)), tuple_separator, '\\'); } - static void from_string(memoryview elems, std::tuple& opt) + static void from_string(ArrayView elems, std::tuple& opt) { option_from_string(elems[I], std::get(opt)); TupleOptionDetail::from_string(elems, opt); @@ -124,7 +124,7 @@ struct TupleOptionDetail<0, Types...> return option_to_string(std::get<0>(opt)); } - static void from_string(memoryview elems, std::tuple& opt) + static void from_string(ArrayView elems, std::tuple& opt) { option_from_string(elems[0], std::get<0>(opt)); } diff --git a/src/parameters_parser.hh b/src/parameters_parser.hh index 62d784e6..cf60e892 100644 --- a/src/parameters_parser.hh +++ b/src/parameters_parser.hh @@ -3,14 +3,14 @@ #include "exception.hh" #include "id_map.hh" -#include "memoryview.hh" +#include "array_view.hh" #include "flags.hh" #include "string.hh" namespace Kakoune { -using ParameterList = memoryview; +using ParameterList = ArrayView; struct parameter_error : public runtime_error { diff --git a/src/register.hh b/src/register.hh index 13833490..de9dedf6 100644 --- a/src/register.hh +++ b/src/register.hh @@ -1,7 +1,7 @@ #ifndef register_hh_INCLUDED #define register_hh_INCLUDED -#include "memoryview.hh" +#include "array_view.hh" #include "string.hh" namespace Kakoune @@ -13,9 +13,9 @@ class Register { public: virtual ~Register() {} - virtual Register& operator=(memoryview values) = 0; + virtual Register& operator=(ArrayView values) = 0; - virtual memoryview values(const Context& context) = 0; + virtual ArrayView values(const Context& context) = 0; }; } diff --git a/src/register_manager.cc b/src/register_manager.cc index 31255805..abbd63f9 100644 --- a/src/register_manager.cc +++ b/src/register_manager.cc @@ -12,18 +12,18 @@ namespace Kakoune class StaticRegister : public Register { public: - Register& operator=(memoryview values) override + Register& operator=(ArrayView values) override { m_content = std::vector(values.begin(), values.end()); return *this; } - memoryview values(const Context&) override + ArrayView values(const Context&) override { if (m_content.empty()) - return memoryview(ms_empty); + return ArrayView(ms_empty); else - return memoryview(m_content); + return ArrayView(m_content); } protected: std::vector m_content; @@ -41,12 +41,12 @@ public: DynamicRegister(RegisterRetriever function) : m_function(std::move(function)) {} - Register& operator=(memoryview values) override + Register& operator=(ArrayView values) override { throw runtime_error("this register is not assignable"); } - memoryview values(const Context& context) override + ArrayView values(const Context& context) override { m_content = m_function(context); return StaticRegister::values(context); diff --git a/src/remote.cc b/src/remote.cc index 08a13e39..0cd2a23c 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -68,7 +68,7 @@ public: } template - void write(memoryview view) + void write(ArrayView view) { write(view.size()); for (auto& val : view) @@ -78,7 +78,7 @@ public: template void write(const std::vector& vec) { - write(memoryview(vec)); + write(ArrayView(vec)); } template @@ -249,7 +249,7 @@ public: RemoteUI(int socket); ~RemoteUI(); - void menu_show(memoryview choices, + void menu_show(ArrayView choices, CharCoord anchor, Face fg, Face bg, MenuStyle style) override; void menu_select(int selected) override; @@ -298,7 +298,7 @@ RemoteUI::~RemoteUI() m_socket_watcher.close_fd(); } -void RemoteUI::menu_show(memoryview choices, +void RemoteUI::menu_show(ArrayView choices, CharCoord anchor, Face fg, Face bg, MenuStyle style) { diff --git a/src/selection.cc b/src/selection.cc index d5f72eb3..cc98c918 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -196,7 +196,7 @@ const Buffer::Change* backward_sorted_until(const Buffer::Change* first, const B return last; } -void update_forward(memoryview changes, std::vector& selections, size_t& main) +void update_forward(ArrayView changes, std::vector& selections, size_t& main) { ForwardChangesTracker changes_tracker; @@ -221,7 +221,7 @@ void update_forward(memoryview changes, std::vector& kak_assert(std::is_sorted(selections.begin(), selections.end(), compare_selections)); } -void update_backward(memoryview changes, std::vector& selections, size_t& main) +void update_backward(ArrayView changes, std::vector& selections, size_t& main) { ForwardChangesTracker changes_tracker; @@ -463,7 +463,7 @@ BufferIterator prepare_insert(Buffer& buffer, const Selection& sel, InsertMode m return {}; } -void SelectionList::insert(memoryview strings, InsertMode mode, +void SelectionList::insert(ArrayView strings, InsertMode mode, bool select_inserted) { if (strings.empty()) diff --git a/src/selection.hh b/src/selection.hh index 4bd25e94..c426702f 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -124,7 +124,7 @@ struct SelectionList size_t timestamp() const { return m_timestamp; } void update_timestamp() { m_timestamp = m_buffer->timestamp(); } - void insert(memoryview strings, InsertMode mode, + void insert(ArrayView strings, InsertMode mode, bool select_inserted = false); void erase(); diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 0888f99a..2a995b13 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -29,7 +29,7 @@ ShellManager::ShellManager() } String ShellManager::eval(StringView cmdline, const Context& context, - memoryview params, + ArrayView params, const EnvVarMap& env_vars, int* exit_status) { @@ -38,7 +38,7 @@ String ShellManager::eval(StringView cmdline, const Context& context, String ShellManager::pipe(StringView input, StringView cmdline, const Context& context, - memoryview params, + ArrayView params, const EnvVarMap& env_vars, int* exit_status) { diff --git a/src/shell_manager.hh b/src/shell_manager.hh index 741faabc..cf079b24 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -9,7 +9,7 @@ namespace Kakoune { class Context; -template class memoryview; +template class ArrayView; class String; class StringView; @@ -21,13 +21,13 @@ public: ShellManager(); String eval(StringView cmdline, const Context& context, - memoryview params, + ArrayView params, const EnvVarMap& env_vars, int* exit_status = nullptr); String pipe(StringView input, StringView cmdline, const Context& context, - memoryview params, + ArrayView params, const EnvVarMap& env_vars, int* exit_status = nullptr); diff --git a/src/user_interface.hh b/src/user_interface.hh index f401bf14..a912b417 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -15,7 +15,7 @@ class DisplayLine; struct CharCoord; struct Face; struct Key; -template class memoryview; +template class ArrayView; enum class MenuStyle { @@ -41,7 +41,7 @@ class UserInterface : public SafeCountable public: virtual ~UserInterface() {} - virtual void menu_show(memoryview choices, + virtual void menu_show(ArrayView choices, CharCoord anchor, Face fg, Face bg, MenuStyle style) = 0; virtual void menu_select(int selected) = 0;