From 96e6cafdaa726e4a8a0382483ae24f4ec2e71202 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sun, 20 Oct 2024 13:22:48 +0200 Subject: [PATCH] refactor(checksum): use array instead of unordered_set --- src/checksum.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/checksum.cpp b/src/checksum.cpp index fd4c7d4e..ed6747e5 100644 --- a/src/checksum.cpp +++ b/src/checksum.cpp @@ -25,7 +25,8 @@ #include #include #include -#include +#include +#include #include @@ -42,9 +43,11 @@ namespace dwarfs { namespace { -std::unordered_set supported_algorithms{ - "xxh3-64", - "xxh3-128", +using namespace std::string_view_literals; + +constexpr std::array supported_algorithms{ + "xxh3-64"sv, + "xxh3-128"sv, }; constexpr std::array unsupported_algorithms{ @@ -207,7 +210,10 @@ bool verify_impl(T&& alg, void const* data, size_t size, const void* digest, } // namespace bool checksum::is_available(std::string const& algo) { - return supported_algorithms.count(algo) or checksum_evp::is_available(algo); + // TODO: C++23: use std::ranges::contains + return std::ranges::find(supported_algorithms, algo) != + supported_algorithms.end() || + checksum_evp::is_available(algo); } std::vector checksum::available_algorithms() {