mirror of
https://github.com/NixOS/nix
synced 2025-07-05 12:21:48 +02:00
Merge pull request #11092 from DeterminateSystems/hash-SourcePath
Use std::unordered_map for the EvalState caches
This commit is contained in:
commit
9c6678da0e
4 changed files with 37 additions and 8 deletions
|
@ -9,6 +9,8 @@
|
|||
#include "canon-path.hh"
|
||||
#include "source-accessor.hh"
|
||||
|
||||
#include <boost/functional/hash.hpp> // for boost::hash_combine
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
|
@ -114,8 +116,21 @@ struct SourcePath
|
|||
{
|
||||
return {accessor, accessor->resolveSymlinks(path, mode)};
|
||||
}
|
||||
|
||||
friend class std::hash<nix::SourcePath>;
|
||||
};
|
||||
|
||||
std::ostream & operator << (std::ostream & str, const SourcePath & path);
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct std::hash<nix::SourcePath>
|
||||
{
|
||||
std::size_t operator()(const nix::SourcePath & s) const noexcept
|
||||
{
|
||||
std::size_t hash = 0;
|
||||
hash_combine(hash, s.accessor->number, s.path);
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -375,4 +375,18 @@ inline std::string operator + (std::string_view s1, const char * s2)
|
|||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* hash_combine() from Boost. Hash several hashable values together
|
||||
* into a single hash.
|
||||
*/
|
||||
inline void hash_combine(std::size_t & seed) { }
|
||||
|
||||
template <typename T, typename... Rest>
|
||||
inline void hash_combine(std::size_t & seed, const T & v, Rest... rest)
|
||||
{
|
||||
std::hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
||||
hash_combine(seed, rest...);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue