From 6ed01f402b3a54495c8d9e462b7674864fbbe402 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 9 Aug 2024 18:33:32 +1000 Subject: Reduce headers dependency graph Move more code into the implementation files to reduce the amount of code pulled by headers. --- src/alias_registry.hh | 1 + src/assert.cc | 1 + src/completion.cc | 1 + src/display_buffer.hh | 2 ++ src/file.hh | 1 + src/hook_manager.hh | 1 + src/input_handler.hh | 1 + src/json.hh | 1 + src/json_ui.cc | 1 + src/keymap_manager.cc | 1 + src/keys.cc | 1 + src/normal.cc | 2 +- src/option_manager.hh | 1 + src/option_types.hh | 2 +- src/parameters_parser.cc | 1 + src/ranked_match.cc | 1 + src/regex_impl.cc | 1 + src/regex_impl.hh | 1 + src/register_manager.cc | 1 + src/register_manager.hh | 1 + src/selection.cc | 34 ++++++++++++++++++++++++++++++++++ src/selection.hh | 45 +++++++++++++++++---------------------------- src/selectors.hh | 1 + src/unicode.hh | 9 ++++++--- 24 files changed, 79 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/alias_registry.hh b/src/alias_registry.hh index 1b7a49eb..32f9e2fb 100644 --- a/src/alias_registry.hh +++ b/src/alias_registry.hh @@ -3,6 +3,7 @@ #include "safe_ptr.hh" #include "string.hh" +#include "ranges.hh" #include "hash_map.hh" namespace Kakoune diff --git a/src/assert.cc b/src/assert.cc index e755e8ba..7be769a1 100644 --- a/src/assert.cc +++ b/src/assert.cc @@ -1,6 +1,7 @@ #include "assert.hh" #include "backtrace.hh" +#include "format.hh" #include "buffer_utils.hh" #include "exception.hh" diff --git a/src/completion.cc b/src/completion.cc index 762a0413..60e79e07 100644 --- a/src/completion.cc +++ b/src/completion.cc @@ -2,6 +2,7 @@ #include "file.hh" #include "context.hh" #include "option_types.hh" +#include "option_manager.hh" #include "regex.hh" namespace Kakoune diff --git a/src/display_buffer.hh b/src/display_buffer.hh index c4ea6fb5..b1a18098 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -7,6 +7,8 @@ #include "string.hh" #include "vector.hh" #include "hash_map.hh" +#include "ranges.hh" + #include namespace Kakoune diff --git a/src/file.hh b/src/file.hh index cfc68ac2..9411fd78 100644 --- a/src/file.hh +++ b/src/file.hh @@ -6,6 +6,7 @@ #include "meta.hh" #include "string.hh" #include "units.hh" +#include "constexpr_utils.hh" #include "vector.hh" #include diff --git a/src/hook_manager.hh b/src/hook_manager.hh index bee06064..114deefd 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -6,6 +6,7 @@ #include "safe_ptr.hh" #include "meta.hh" #include "enum.hh" +#include "constexpr_utils.hh" #include diff --git a/src/input_handler.hh b/src/input_handler.hh index dd475c92..fa7c91b1 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -5,6 +5,7 @@ #include "constexpr_utils.hh" #include "context.hh" #include "env_vars.hh" +#include "enum.hh" #include "face.hh" #include "normal.hh" #include "optional.hh" diff --git a/src/json.hh b/src/json.hh index 84c14d36..6765c793 100644 --- a/src/json.hh +++ b/src/json.hh @@ -3,6 +3,7 @@ #include "hash_map.hh" #include "string.hh" +#include "string_utils.hh" #include "value.hh" namespace Kakoune diff --git a/src/json_ui.cc b/src/json_ui.cc index 01768897..1efbf2a5 100644 --- a/src/json_ui.cc +++ b/src/json_ui.cc @@ -8,6 +8,7 @@ #include "keys.hh" #include "ranges.hh" #include "string_utils.hh" +#include "format.hh" #include #include diff --git a/src/keymap_manager.cc b/src/keymap_manager.cc index 583fb2e7..8894267a 100644 --- a/src/keymap_manager.cc +++ b/src/keymap_manager.cc @@ -4,6 +4,7 @@ #include "assert.hh" #include "exception.hh" #include "format.hh" +#include "ranges.hh" #include diff --git a/src/keys.cc b/src/keys.cc index 5ba44181..4a14e0fc 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -6,6 +6,7 @@ #include "unit_tests.hh" #include "utf8_iterator.hh" #include "utils.hh" +#include "format.hh" #include "string_utils.hh" namespace Kakoune diff --git a/src/normal.cc b/src/normal.cc index ea183bc4..5a7c4e58 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1841,7 +1841,7 @@ SelectionList read_selections_from_register(char reg, const Context& context) const auto buffer_name = StringView{ content[0].begin (), end_content[1].begin () - 1 }; Buffer& buffer = BufferManager::instance().get_buffer(buffer_name); - return selection_list_from_strings(buffer, ColumnType::Byte, content | skip(1), timestamp, main); + return selection_list_from_strings(buffer, ColumnType::Byte, content.subrange(1), timestamp, main); } enum class CombineOp diff --git a/src/option_manager.hh b/src/option_manager.hh index 3a4bb5a5..480b589b 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -8,6 +8,7 @@ #include "ranges.hh" #include "utils.hh" #include "vector.hh" +#include "format.hh" #include "string_utils.hh" #include diff --git a/src/option_types.hh b/src/option_types.hh index 40d367df..fedc476f 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -7,9 +7,9 @@ #include "flags.hh" #include "hash_map.hh" #include "option.hh" -#include "ranges.hh" #include "string.hh" #include "string_utils.hh" +#include "format.hh" #include "units.hh" #include diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc index 75575323..5d2858ed 100644 --- a/src/parameters_parser.cc +++ b/src/parameters_parser.cc @@ -1,5 +1,6 @@ #include "parameters_parser.hh" +#include "ranges.hh" #include "flags.hh" namespace Kakoune diff --git a/src/ranked_match.cc b/src/ranked_match.cc index a13decdf..87bcece7 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -4,6 +4,7 @@ #include "unit_tests.hh" #include "utf8_iterator.hh" #include "optional.hh" +#include "ranges.hh" #include diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 2cebf964..f6393b56 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -9,6 +9,7 @@ #include "format.hh" #include "vector.hh" #include "utils.hh" +#include "ranges.hh" #include #include diff --git a/src/regex_impl.hh b/src/regex_impl.hh index b772169d..7f3eb495 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -9,6 +9,7 @@ #include "utils.hh" #include +#include namespace Kakoune { diff --git a/src/register_manager.cc b/src/register_manager.cc index bb198dc6..254104a4 100644 --- a/src/register_manager.cc +++ b/src/register_manager.cc @@ -4,6 +4,7 @@ #include "context.hh" #include "hash_map.hh" #include "format.hh" +#include "hook_manager.hh" namespace Kakoune { diff --git a/src/register_manager.hh b/src/register_manager.hh index 2e760e6f..c7ca8590 100644 --- a/src/register_manager.hh +++ b/src/register_manager.hh @@ -6,6 +6,7 @@ #include "exception.hh" #include "utils.hh" #include "hash_map.hh" +#include "ranges.hh" #include "string.hh" #include "vector.hh" diff --git a/src/selection.cc b/src/selection.cc index f0f0270c..03dd4721 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -7,6 +7,8 @@ namespace Kakoune { +SelectionList::~SelectionList() = default; + SelectionList::SelectionList(Buffer& buffer, Selection s, size_t timestamp) : m_selections({ std::move(s) }), m_buffer(&buffer), m_timestamp(timestamp) { @@ -27,6 +29,11 @@ SelectionList::SelectionList(Buffer& buffer, Vector list, size_t time SelectionList::SelectionList(Buffer& buffer, Vector list) : SelectionList(buffer, std::move(list), buffer.timestamp()) {} +SelectionList::SelectionList(const SelectionList&) = default; +SelectionList::SelectionList(SelectionList&&) = default; +SelectionList& SelectionList::operator=(const SelectionList&) = default; +SelectionList& SelectionList::operator=(SelectionList&&) = default; + void SelectionList::remove(size_t index) { m_selections.erase(begin() + index); @@ -538,4 +545,31 @@ Selection selection_from_string(ColumnType column_type, const Buffer& buffer, St return Selection{anchor, cursor}; } +SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, ConstArrayView descs, size_t timestamp, size_t main, ColumnCount tabstop) +{ + if ((column_type != ColumnType::Byte and timestamp != buffer.timestamp()) or timestamp > buffer.timestamp()) + throw runtime_error{format("invalid timestamp '{}'", timestamp)}; + + auto from_string = [&](StringView desc) { + return selection_from_string(column_type, buffer, desc, tabstop); + }; + + auto sels = descs | transform(from_string) | gather>(); + if (sels.empty()) + throw runtime_error{"empty selection description"}; + if (main >= sels.size()) + throw runtime_error{"invalid main selection index"}; + + sort_selections(sels, main); + merge_overlapping_selections(sels, main); + if (timestamp < buffer.timestamp()) + update_selections(sels, main, buffer, timestamp); + else + clamp_selections(sels, buffer); + + SelectionList res{buffer, std::move(sels)}; + res.set_main_index(main); + return res; +} + } diff --git a/src/selection.hh b/src/selection.hh index 509a527d..ede4fa7b 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -1,13 +1,21 @@ #ifndef selection_hh_INCLUDED #define selection_hh_INCLUDED -#include "buffer.hh" +#include "coord.hh" +#include "range.hh" +#include "safe_ptr.hh" +#include "utils.hh" +#include "string.hh" +#include "vector.hh" #include namespace Kakoune { +class Buffer; +using BufferRange = Range; + using CaptureList = Vector; constexpr ColumnCount max_column{std::numeric_limits::max()}; @@ -84,11 +92,18 @@ struct SelectionList { static constexpr MemoryDomain Domain = MemoryDomain::Selections; + ~SelectionList(); SelectionList(Buffer& buffer, Selection s); SelectionList(Buffer& buffer, Selection s, size_t timestamp); SelectionList(Buffer& buffer, Vector s); SelectionList(Buffer& buffer, Vector s, size_t timestamp); + SelectionList(const SelectionList&); + SelectionList(SelectionList&&); + + SelectionList& operator=(const SelectionList&); + SelectionList& operator=(SelectionList&&); + void update(bool merge = true); void check_invariant() const; @@ -166,33 +181,7 @@ String selection_to_string(ColumnType column_type, const Buffer& buffer, const S String selection_list_to_string(ColumnType column_type, const SelectionList& selections, ColumnCount tabstop = -1); -template -SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, StringArray&& descs, size_t timestamp, size_t main, ColumnCount tabstop = -1) -{ - if ((column_type != ColumnType::Byte and timestamp != buffer.timestamp()) or timestamp > buffer.timestamp()) - throw runtime_error{format("invalid timestamp '{}'", timestamp)}; - - auto from_string = [&](StringView desc) { - return selection_from_string(column_type, buffer, desc, tabstop); - }; - - auto sels = descs | transform(from_string) | gather>(); - if (sels.empty()) - throw runtime_error{"empty selection description"}; - if (main >= sels.size()) - throw runtime_error{"invalid main selection index"}; - - sort_selections(sels, main); - merge_overlapping_selections(sels, main); - if (timestamp < buffer.timestamp()) - update_selections(sels, main, buffer, timestamp); - else - clamp_selections(sels, buffer); - - SelectionList res{buffer, std::move(sels)}; - res.set_main_index(main); - return res; -} +SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, ConstArrayView descs, size_t timestamp, size_t main, ColumnCount tabstop = -1); } diff --git a/src/selectors.hh b/src/selectors.hh index a9a61314..e947250f 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -6,6 +6,7 @@ #include "meta.hh" #include "unicode.hh" #include "vector.hh" +#include "constexpr_utils.hh" namespace Kakoune { diff --git a/src/unicode.hh b/src/unicode.hh index 0acf4005..5ce63f4b 100644 --- a/src/unicode.hh +++ b/src/unicode.hh @@ -5,7 +5,6 @@ #include #include "array_view.hh" -#include "ranges.hh" #include "units.hh" namespace Kakoune @@ -75,8 +74,12 @@ enum WordType { Word, WORD }; template inline bool is_word(Codepoint c, ConstArrayView extra_word_chars = {'_'}) noexcept { - return (c < 128 ? is_basic_alpha(c) or is_basic_digit(c) : iswalnum((wchar_t)c)) or - contains(extra_word_chars, c); + if (c < 128 ? is_basic_alpha(c) or is_basic_digit(c) : iswalnum((wchar_t)c)) + return true; + for (auto cp : extra_word_chars) + if (c == cp) + return true; + return false; } template<> -- cgit v1.2.3