Skip to content
Snippets Groups Projects
Commit fcca618c authored by Adrien Béraud's avatar Adrien Béraud
Browse files

infohash: improve getRandom performance

Generate random hash in 32 bits chunks
instead of 8 bits chunks.
parent 73bcebf3
Branches
Tags
No related merge requests found
......@@ -64,12 +64,10 @@ InfoHash::getRandom()
{
InfoHash h;
crypto::random_device rdev;
#ifdef _WIN32
static std::uniform_int_distribution<int> rand_byte{ 0, std::numeric_limits<uint8_t>::max() };
#else
static std::uniform_int_distribution<uint8_t> rand_byte;
#endif
std::generate(h.begin(), h.end(), std::bind(rand_byte, std::ref(rdev)));
std::uniform_int_distribution<uint32_t> rand_int;
auto a = reinterpret_cast<uint32_t*>(&(*h.begin()));
auto b = reinterpret_cast<uint32_t*>(&(*h.end()));
std::generate(a, b, std::bind(rand_int, std::ref(rdev)));
return h;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment