1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 22:42:41 +01:00

Encapsulate invalidBase32, avoid 0xFF magic number

This keeps things fast by making the function inline, but also prevents
people from having to know about the `0xFF` implementation detail
directly, instead making one go through a `std::optional` (which could be
fused away with a sufficiently smart compiler).

Additionally, the base "nix32" implementation is moved to its own header
file pair, as it is logically distinct and prior to the `Hash` data
type. It would probably be nice to do this with all the hash format
implementations.
This commit is contained in:
John Ericson 2025-08-04 14:31:14 -04:00
parent 6ab8cbe31a
commit 23c87d8a21
8 changed files with 101 additions and 38 deletions

View file

@ -1,5 +1,6 @@
#include "nix/util/references.hh"
#include "nix/store/path.hh"
#include "nix/util/base-nix-32.hh"
#include <benchmark/benchmark.h>
@ -10,9 +11,9 @@ using namespace nix;
template<typename OIt>
static void randomReference(std::mt19937 & urng, OIt outIter)
{
auto dist = std::uniform_int_distribution<std::size_t>(0, nix32Chars.size() - 1);
auto dist = std::uniform_int_distribution<std::size_t>(0, BaseNix32::characters.size() - 1);
dist(urng);
std::generate_n(outIter, StorePath::HashLen, [&]() { return nix32Chars[dist(urng)]; });
std::generate_n(outIter, StorePath::HashLen, [&]() { return BaseNix32::characters[dist(urng)]; });
}
/**