mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 21:16:02 +01:00
hashmaps with string keys: add transparent lookups
This commit is contained in:
parent
9f2b6a1b94
commit
9dbc2cae4f
3 changed files with 22 additions and 12 deletions
|
|
@ -474,7 +474,8 @@ private:
|
||||||
|
|
||||||
LookupPath lookupPath;
|
LookupPath lookupPath;
|
||||||
|
|
||||||
boost::unordered_flat_map<std::string, std::optional<SourcePath>> lookupPathResolved;
|
boost::unordered_flat_map<std::string, std::optional<SourcePath>, StringViewHash, std::equal_to<>>
|
||||||
|
lookupPathResolved;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache used by prim_match().
|
* Cache used by prim_match().
|
||||||
|
|
@ -751,8 +752,8 @@ public:
|
||||||
boost::unordered_flat_map<
|
boost::unordered_flat_map<
|
||||||
std::string,
|
std::string,
|
||||||
Value *,
|
Value *,
|
||||||
std::hash<std::string>,
|
StringViewHash,
|
||||||
std::equal_to<std::string>,
|
std::equal_to<>,
|
||||||
traceable_allocator<std::pair<const std::string, Value *>>>
|
traceable_allocator<std::pair<const std::string, Value *>>>
|
||||||
internalPrimOps;
|
internalPrimOps;
|
||||||
|
|
||||||
|
|
@ -1019,7 +1020,7 @@ private:
|
||||||
|
|
||||||
bool countCalls;
|
bool countCalls;
|
||||||
|
|
||||||
typedef boost::unordered_flat_map<std::string, size_t> PrimOpCalls;
|
typedef boost::unordered_flat_map<std::string, size_t, StringViewHash, std::equal_to<>> PrimOpCalls;
|
||||||
PrimOpCalls primOpCalls;
|
PrimOpCalls primOpCalls;
|
||||||
|
|
||||||
typedef boost::unordered_flat_map<ExprLambda *, size_t> FunctionCalls;
|
typedef boost::unordered_flat_map<ExprLambda *, size_t> FunctionCalls;
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,12 @@ Roots LocalStore::findRoots(bool censor)
|
||||||
/**
|
/**
|
||||||
* Key is a mere string because cannot has path with macOS's libc++
|
* Key is a mere string because cannot has path with macOS's libc++
|
||||||
*/
|
*/
|
||||||
typedef boost::unordered_flat_map<std::string, boost::unordered_flat_set<std::string>> UncheckedRoots;
|
typedef boost::unordered_flat_map<
|
||||||
|
std::string,
|
||||||
|
boost::unordered_flat_set<std::string, StringViewHash, std::equal_to<>>,
|
||||||
|
StringViewHash,
|
||||||
|
std::equal_to<>>
|
||||||
|
UncheckedRoots;
|
||||||
|
|
||||||
static void readProcLink(const std::filesystem::path & file, UncheckedRoots & roots)
|
static void readProcLink(const std::filesystem::path & file, UncheckedRoots & roots)
|
||||||
{
|
{
|
||||||
|
|
@ -325,7 +330,7 @@ static void readProcLink(const std::filesystem::path & file, UncheckedRoots & ro
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
if (buf.is_absolute())
|
if (buf.is_absolute())
|
||||||
roots[buf.string()].emplace(file.string());
|
roots[buf].emplace(file.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string quoteRegexChars(const std::string & raw)
|
static std::string quoteRegexChars(const std::string & raw)
|
||||||
|
|
@ -466,7 +471,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
{
|
{
|
||||||
// The temp roots only store the hash part to make it easier to
|
// The temp roots only store the hash part to make it easier to
|
||||||
// ignore suffixes like '.lock', '.chroot' and '.check'.
|
// ignore suffixes like '.lock', '.chroot' and '.check'.
|
||||||
boost::unordered_flat_set<std::string> tempRoots;
|
boost::unordered_flat_set<std::string, StringViewHash, std::equal_to<>> tempRoots;
|
||||||
|
|
||||||
// Hash part of the store path currently being deleted, if
|
// Hash part of the store path currently being deleted, if
|
||||||
// any.
|
// any.
|
||||||
|
|
@ -575,9 +580,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
auto storePath = maybeParseStorePath(path);
|
auto storePath = maybeParseStorePath(path);
|
||||||
if (storePath) {
|
if (storePath) {
|
||||||
debug("got new GC root '%s'", path);
|
debug("got new GC root '%s'", path);
|
||||||
auto hashPart = std::string(storePath->hashPart());
|
auto hashPart = storePath->hashPart();
|
||||||
auto shared(_shared.lock());
|
auto shared(_shared.lock());
|
||||||
shared->tempRoots.insert(hashPart);
|
shared->tempRoots.emplace(hashPart);
|
||||||
/* If this path is currently being
|
/* If this path is currently being
|
||||||
deleted, then we have to wait until
|
deleted, then we have to wait until
|
||||||
deletion is finished to ensure that
|
deletion is finished to ensure that
|
||||||
|
|
@ -629,7 +634,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
Roots tempRoots;
|
Roots tempRoots;
|
||||||
findTempRoots(tempRoots, true);
|
findTempRoots(tempRoots, true);
|
||||||
for (auto & root : tempRoots) {
|
for (auto & root : tempRoots) {
|
||||||
_shared.lock()->tempRoots.insert(std::string(root.first.hashPart()));
|
_shared.lock()->tempRoots.emplace(root.first.hashPart());
|
||||||
roots.insert(root.first);
|
roots.insert(root.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -736,7 +741,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto hashPart = std::string(path->hashPart());
|
auto hashPart = path->hashPart();
|
||||||
auto shared(_shared.lock());
|
auto shared(_shared.lock());
|
||||||
if (shared->tempRoots.count(hashPart)) {
|
if (shared->tempRoots.count(hashPart)) {
|
||||||
debug("cannot delete '%s' because it's a temporary root", printStorePath(*path));
|
debug("cannot delete '%s' because it's a temporary root", printStorePath(*path));
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
typedef boost::unordered_flat_map<StorePath, boost::unordered_flat_set<std::string>, std::hash<StorePath>> Roots;
|
typedef boost::unordered_flat_map<
|
||||||
|
StorePath,
|
||||||
|
boost::unordered_flat_set<std::string, StringViewHash, std::equal_to<>>,
|
||||||
|
std::hash<StorePath>>
|
||||||
|
Roots;
|
||||||
|
|
||||||
struct GCOptions
|
struct GCOptions
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue