core: Reuse a global hasher instance
This commit is contained in:
@@ -32,6 +32,13 @@ namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Hash");
|
||||
|
||||
Hasher& GetStaticHash (void)
|
||||
{
|
||||
static Hasher g_hasher = Hasher ();
|
||||
g_hasher.clear();
|
||||
return g_hasher;
|
||||
}
|
||||
|
||||
Hasher::Hasher ()
|
||||
{
|
||||
m_impl = Create <Hash::Function::Murmur3> ();
|
||||
|
||||
@@ -271,32 +271,38 @@ Hasher::GetHash64 (const std::string s)
|
||||
Global hash functions, inlined for rvo
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Get a reference to the static global hasher at g_hasher
|
||||
* \return Reference to the static Hasher instance.
|
||||
*/
|
||||
Hasher& GetStaticHash (void);
|
||||
|
||||
inline
|
||||
uint32_t
|
||||
Hash32 (const char * buffer, const std::size_t size)
|
||||
{
|
||||
return Hasher ().GetHash32 (buffer, size);
|
||||
return GetStaticHash ().GetHash32 (buffer, size);
|
||||
}
|
||||
|
||||
inline
|
||||
uint64_t
|
||||
Hash64 (const char * buffer, const std::size_t size)
|
||||
{
|
||||
return Hasher ().GetHash64 (buffer, size);
|
||||
return GetStaticHash ().GetHash64 (buffer, size);
|
||||
}
|
||||
|
||||
inline
|
||||
uint32_t
|
||||
Hash32 (const std::string s)
|
||||
{
|
||||
return Hasher ().GetHash32 (s);
|
||||
return GetStaticHash ().GetHash32 (s);
|
||||
}
|
||||
|
||||
inline
|
||||
uint64_t
|
||||
Hash64 (const std::string s)
|
||||
{
|
||||
return Hasher ().GetHash64 (s);
|
||||
return GetStaticHash ().GetHash64 (s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user