File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change 3
3
#include " nix/util/signals.hh"
4
4
#include " nix/util/sync.hh"
5
5
6
- #include < unordered_map >
6
+ #include < boost/unordered/concurrent_flat_map.hpp >
7
7
8
8
namespace nix {
9
9
@@ -88,25 +88,23 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path)
88
88
89
89
std::optional<struct stat > PosixSourceAccessor::cachedLstat (const CanonPath & path)
90
90
{
91
- static SharedSync<std::unordered_map<Path, std::optional<struct stat >>> _cache;
91
+ using Cache = boost::concurrent_flat_map<Path, std::optional<struct stat >>;
92
+ static Cache cache;
92
93
93
94
// Note: we convert std::filesystem::path to Path because the
94
95
// former is not hashable on libc++.
95
96
Path absPath = makeAbsPath (path).string ();
96
97
97
- {
98
- auto cache (_cache.readLock ());
99
- auto i = cache->find (absPath);
100
- if (i != cache->end ())
101
- return i->second ;
102
- }
98
+ std::optional<Cache::mapped_type> res;
99
+ cache.cvisit (absPath, [&](auto & x) { res.emplace (x.second ); });
100
+ if (res)
101
+ return *res;
103
102
104
103
auto st = nix::maybeLstat (absPath.c_str ());
105
104
106
- auto cache (_cache.lock ());
107
- if (cache->size () >= 16384 )
108
- cache->clear ();
109
- cache->emplace (absPath, st);
105
+ if (cache.size () >= 16384 )
106
+ cache.clear ();
107
+ cache.emplace (absPath, st);
110
108
111
109
return st;
112
110
}
You can’t perform that action at this time.
0 commit comments