Skip to content

Commit

Permalink
refactor(checksum): use array<string_view> instead of unordered_set<s…
Browse files Browse the repository at this point in the history
…tring>
  • Loading branch information
mhx committed Nov 20, 2024
1 parent ca69d2b commit 96e6caf
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include <cstring>
#include <functional>
#include <ostream>
#include <unordered_set>
#include <ranges>
#include <string_view>

#include <openssl/evp.h>

Expand All @@ -42,9 +43,11 @@ namespace dwarfs {

namespace {

std::unordered_set<std::string> 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{
Expand Down Expand Up @@ -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<std::string> checksum::available_algorithms() {
Expand Down

0 comments on commit 96e6caf

Please sign in to comment.