mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Add getConcurrent helper function
This commit is contained in:
parent
377b60ee9b
commit
7f9b5226af
2 changed files with 12 additions and 3 deletions
|
|
@ -218,6 +218,17 @@ typename T::mapped_type * get(T & map, K & key)
|
|||
template<class T>
|
||||
typename T::mapped_type * get(T && map, const typename T::key_type & key) = delete;
|
||||
|
||||
/**
|
||||
* Look up a value in a `boost::concurrent_flat_map`.
|
||||
*/
|
||||
template<class T>
|
||||
std::optional<typename T::mapped_type> getConcurrent(const T & map, const typename T::key_type & key)
|
||||
{
|
||||
std::optional<typename T::mapped_type> res;
|
||||
map.cvisit(key, [&](auto & x) { res = x.second; });
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value for the specified key from an associate container, or a default value if the key isn't present.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -95,9 +95,7 @@ std::optional<struct stat> PosixSourceAccessor::cachedLstat(const CanonPath & pa
|
|||
// former is not hashable on libc++.
|
||||
Path absPath = makeAbsPath(path).string();
|
||||
|
||||
std::optional<Cache::mapped_type> res;
|
||||
cache.cvisit(absPath, [&](auto & x) { res.emplace(x.second); });
|
||||
if (res)
|
||||
if (auto res = getConcurrent(cache, absPath))
|
||||
return *res;
|
||||
|
||||
auto st = nix::maybeLstat(absPath.c_str());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue