mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 03:17:15 +02:00
Improve the performance of hash_value and operator== in benchmark/uuid.cpp
This commit is contained in:
@ -24,6 +24,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
@ -55,12 +56,20 @@ struct uuid
|
|||||||
|
|
||||||
inline friend std::size_t hash_value( uuid const& u ) noexcept
|
inline friend std::size_t hash_value( uuid const& u ) noexcept
|
||||||
{
|
{
|
||||||
return boost::hash_value( u.data );
|
std::uint64_t low = boost::endian::load_little_u64( u.data + 0 );
|
||||||
|
std::uint64_t high = boost::endian::load_little_u64( u.data + 8 );
|
||||||
|
|
||||||
|
std::size_t r = 0;
|
||||||
|
|
||||||
|
boost::hash_combine( r, low );
|
||||||
|
boost::hash_combine( r, high );
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline friend bool operator==( uuid const& u1, uuid const& u2 ) noexcept
|
inline friend bool operator==( uuid const& u1, uuid const& u2 ) noexcept
|
||||||
{
|
{
|
||||||
return std::equal( u1.data + 0, u1.data + 16, u2.data );
|
return std::memcmp( u1.data, u2.data, 16 ) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,7 +80,7 @@ template<> struct hash< ::uuid >
|
|||||||
{
|
{
|
||||||
std::size_t operator()( uuid const& u ) const noexcept
|
std::size_t operator()( uuid const& u ) const noexcept
|
||||||
{
|
{
|
||||||
return boost::hash_value( u.data );
|
return hash_value( u );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user