From 5202677d6c97cd84c8a914f7922a438bd9977fbe Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 3 Dec 2024 21:16:30 +0100 Subject: [PATCH] refactor(fragment_order_parser): use constexpr array instead of map --- src/writer/fragment_order_parser.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/writer/fragment_order_parser.cpp b/src/writer/fragment_order_parser.cpp index ef30fe9b..0077e6eb 100644 --- a/src/writer/fragment_order_parser.cpp +++ b/src/writer/fragment_order_parser.cpp @@ -19,12 +19,13 @@ * along with dwarfs. If not, see . */ -#include +#include #include #include #include +#include #include #include #include @@ -36,13 +37,14 @@ namespace dwarfs::writer { namespace { -const std::map order_choices{ +std::array, + 5> constexpr order_choices{{ {"none", fragment_order_mode::NONE}, {"path", fragment_order_mode::PATH}, {"revpath", fragment_order_mode::REVPATH}, {"similarity", fragment_order_mode::SIMILARITY}, {"nilsimsa", fragment_order_mode::NILSIMSA}, -}; +}}; } // namespace @@ -63,7 +65,10 @@ fragment_order_parser::parse(std::string_view arg) const { option_map om(arg); auto algo = om.choice(); - if (auto it = order_choices.find(algo); it != order_choices.end()) { + if (auto it = ranges::find( + order_choices, algo, + &std::pair::first); + it != order_choices.end()) { rv.mode = it->second; } else { throw std::runtime_error(fmt::format("invalid inode order mode: {}", algo));