mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Provide std::hash<SourcePath>
This commit is contained in:
parent
337a5a23b7
commit
cdc23b67a6
3 changed files with 19 additions and 8 deletions
|
@ -1011,7 +1011,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
|
||||||
if (!e)
|
if (!e)
|
||||||
e = parseExprFromFile(resolvedPath);
|
e = parseExprFromFile(resolvedPath);
|
||||||
|
|
||||||
fileParseCache[resolvedPath] = e;
|
fileParseCache.emplace(resolvedPath, e);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto dts = debugRepl
|
auto dts = debugRepl
|
||||||
|
@ -1034,8 +1034,8 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileEvalCache[resolvedPath] = v;
|
fileEvalCache.emplace(resolvedPath, v);
|
||||||
if (path != resolvedPath) fileEvalCache[path] = v;
|
if (path != resolvedPath) fileEvalCache.emplace(path, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -307,15 +307,15 @@ private:
|
||||||
|
|
||||||
/* Cache for calls to addToStore(); maps source paths to the store
|
/* Cache for calls to addToStore(); maps source paths to the store
|
||||||
paths. */
|
paths. */
|
||||||
Sync<std::map<SourcePath, StorePath>> srcToStore;
|
Sync<std::unordered_map<SourcePath, StorePath>> srcToStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache from path names to parse trees.
|
* A cache from path names to parse trees.
|
||||||
*/
|
*/
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::map<SourcePath, Expr *, std::less<SourcePath>, traceable_allocator<std::pair<const SourcePath, Expr *>>> FileParseCache;
|
typedef std::unordered_map<SourcePath, Expr *, std::hash<SourcePath>, std::equal_to<SourcePath>, traceable_allocator<std::pair<const SourcePath, Expr *>>> FileParseCache;
|
||||||
#else
|
#else
|
||||||
typedef std::map<SourcePath, Expr *> FileParseCache;
|
typedef std::unordered_map<SourcePath, Expr *> FileParseCache;
|
||||||
#endif
|
#endif
|
||||||
FileParseCache fileParseCache;
|
FileParseCache fileParseCache;
|
||||||
|
|
||||||
|
@ -323,9 +323,9 @@ private:
|
||||||
* A cache from path names to values.
|
* A cache from path names to values.
|
||||||
*/
|
*/
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::map<SourcePath, Value, std::less<SourcePath>, traceable_allocator<std::pair<const SourcePath, Value>>> FileEvalCache;
|
typedef std::unordered_map<SourcePath, Value, std::hash<SourcePath>, std::equal_to<SourcePath>, traceable_allocator<std::pair<const SourcePath, Value>>> FileEvalCache;
|
||||||
#else
|
#else
|
||||||
typedef std::map<SourcePath, Value> FileEvalCache;
|
typedef std::unordered_map<SourcePath, Value> FileEvalCache;
|
||||||
#endif
|
#endif
|
||||||
FileEvalCache fileEvalCache;
|
FileEvalCache fileEvalCache;
|
||||||
|
|
||||||
|
|
|
@ -115,8 +115,19 @@ struct SourcePath
|
||||||
{
|
{
|
||||||
return {accessor, accessor->resolveSymlinks(path, mode)};
|
return {accessor, accessor->resolveSymlinks(path, mode)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend class std::hash<nix::SourcePath>;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & str, const SourcePath & path);
|
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
|
||||||
|
{
|
||||||
|
return std::hash<decltype(s.path)>{}(s.path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue