From f384932b58c01b6a37f832089a94cfac10fe6b1b Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Wed, 3 Jul 2024 01:30:08 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20gucc:=20refactor=20initcpio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit use ranges instead of explicitly defining begin..end move what we can move --- gucc/include/gucc/initcpio.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/gucc/include/gucc/initcpio.hpp b/gucc/include/gucc/initcpio.hpp index 7cb8a5d..413b6f5 100644 --- a/gucc/include/gucc/initcpio.hpp +++ b/gucc/include/gucc/initcpio.hpp @@ -17,6 +17,7 @@ #endif #include +#include #include #include @@ -30,7 +31,8 @@ namespace gucc::detail { class Initcpio final { public: - explicit Initcpio(const std::string_view& file_path) noexcept : m_file_path(file_path) { } + explicit Initcpio(const std::string_view& file_path) noexcept + : m_file_path(file_path) { } bool parse_file() noexcept; @@ -78,8 +80,8 @@ class Initcpio final { if (ranges::contains(hooks, hook)) { return false; } /* clang-format on */ - const auto& needle_pos = std::find(hooks.begin(), hooks.end(), std::move(needle)); - hooks.insert(needle_pos, hook); + auto&& needle_pos = ranges::find(hooks, std::move(needle)); + hooks.insert(std::move(needle_pos), std::move(hook)); return this->write(); } inline bool insert_hook(std::string&& needle, std::vector&& hook) noexcept { @@ -91,29 +93,29 @@ class Initcpio final { if (filtered_input.empty()) { return false; } /* clang-format on */ - const auto& needle_pos = std::find(hooks.begin(), hooks.end(), std::move(needle)); - hooks.insert(needle_pos, filtered_input.begin(), filtered_input.end()); + auto&& needle_pos = ranges::find(hooks, std::move(needle)); + hooks.insert(std::move(needle_pos), filtered_input.begin(), filtered_input.end()); return this->write(); } inline bool remove_module(std::string&& module) noexcept { /* clang-format off */ if (!this->parse_file()) { return false; } - const auto& needle_pos = std::find(modules.begin(), modules.end(), std::move(module)); + auto&& needle_pos = ranges::find(modules, std::move(module)); if (needle_pos == modules.end()) { return false; } /* clang-format on */ - modules.erase(needle_pos); + modules.erase(std::move(needle_pos)); return this->write(); } inline bool remove_hook(std::string&& hook) noexcept { /* clang-format off */ if (!this->parse_file()) { return false; } - const auto& needle_pos = std::find(hooks.begin(), hooks.end(), std::move(hook)); + auto&& needle_pos = ranges::find(hooks, std::move(hook)); if (needle_pos == hooks.end()) { return false; } /* clang-format on */ - hooks.erase(needle_pos); + hooks.erase(std::move(needle_pos)); return this->write(); }