1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 06:52:43 +01:00

Merge pull request #13926 from NaN-git/opt_boost-unordered

replace all occurences of std::unordered_* by equivalents from boost
This commit is contained in:
Jörg Thalheim 2025-09-12 11:46:42 +02:00 committed by GitHub
commit 377b60ee9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 130 additions and 119 deletions

View file

@ -11,6 +11,7 @@
#include "nix/util/json-utils.hh"
#include <boost/container/small_vector.hpp>
#include <boost/unordered/concurrent_flat_map.hpp>
#include <nlohmann/json.hpp>
namespace nix {
@ -834,7 +835,7 @@ DerivationType BasicDerivation::type() const
throw Error("can't mix derivation output types");
}
Sync<DrvHashes> drvHashes;
DrvHashes drvHashes;
/* pathDerivationModulo and hashDerivationModulo are mutually recursive
*/
@ -844,16 +845,13 @@ Sync<DrvHashes> drvHashes;
*/
static const DrvHash pathDerivationModulo(Store & store, const StorePath & drvPath)
{
{
auto hashes = drvHashes.lock();
auto h = hashes->find(drvPath);
if (h != hashes->end()) {
return h->second;
}
std::optional<DrvHash> hash;
if (drvHashes.cvisit(drvPath, [&hash](const auto & kv) { hash.emplace(kv.second); })) {
return *hash;
}
auto h = hashDerivationModulo(store, store.readInvalidDerivation(drvPath), false);
// Cache it
drvHashes.lock()->insert_or_assign(drvPath, h);
drvHashes.insert_or_assign(drvPath, h);
return h;
}

View file

@ -1,6 +1,7 @@
#include "nix/store/derivations.hh"
#include "nix/store/globals.hh"
#include "nix/store/local-store.hh"
#include "nix/store/path.hh"
#include "nix/util/finally.hh"
#include "nix/util/unix-domain-socket.hh"
#include "nix/util/signals.hh"
@ -13,14 +14,10 @@
# include "nix/util/processes.hh"
#endif
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/unordered_flat_set.hpp>
#include <boost/regex.hpp>
#include <functional>
#include <queue>
#include <algorithm>
#include <random>
#include <climits>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
@ -314,7 +311,12 @@ Roots LocalStore::findRoots(bool censor)
/**
* Key is a mere string because cannot has path with macOS's libc++
*/
typedef std::unordered_map<std::string, std::unordered_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)
{
@ -328,7 +330,7 @@ static void readProcLink(const std::filesystem::path & file, UncheckedRoots & ro
throw;
}
if (buf.is_absolute())
roots[buf.string()].emplace(file.string());
roots[buf].emplace(file.string());
}
static std::string quoteRegexChars(const std::string & raw)
@ -463,13 +465,13 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
bool gcKeepOutputs = settings.gcKeepOutputs;
bool gcKeepDerivations = settings.gcKeepDerivations;
std::unordered_set<StorePath> roots, dead, alive;
boost::unordered_flat_set<StorePath, std::hash<StorePath>> roots, dead, alive;
struct Shared
{
// The temp roots only store the hash part to make it easier to
// ignore suffixes like '.lock', '.chroot' and '.check'.
std::unordered_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
// any.
@ -578,9 +580,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
auto storePath = maybeParseStorePath(path);
if (storePath) {
debug("got new GC root '%s'", path);
auto hashPart = std::string(storePath->hashPart());
auto hashPart = storePath->hashPart();
auto shared(_shared.lock());
shared->tempRoots.insert(hashPart);
shared->tempRoots.emplace(hashPart);
/* If this path is currently being
deleted, then we have to wait until
deletion is finished to ensure that
@ -632,7 +634,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
Roots tempRoots;
findTempRoots(tempRoots, true);
for (auto & root : tempRoots) {
_shared.lock()->tempRoots.insert(std::string(root.first.hashPart()));
_shared.lock()->tempRoots.emplace(root.first.hashPart());
roots.insert(root.first);
}
@ -672,7 +674,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
}
};
std::unordered_map<StorePath, StorePathSet> referrersCache;
boost::unordered_flat_map<StorePath, StorePathSet, std::hash<StorePath>> referrersCache;
/* Helper function that visits all paths reachable from `start`
via the referrers edges and optionally derivers and derivation
@ -739,7 +741,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
return;
{
auto hashPart = std::string(path->hashPart());
auto hashPart = path->hashPart();
auto shared(_shared.lock());
if (shared->tempRoots.count(hashPart)) {
debug("cannot delete '%s' because it's a temporary root", printStorePath(*path));

View file

@ -11,7 +11,7 @@
#include "nix/util/sync.hh"
#include "nix/util/variant-wrapper.hh"
#include <map>
#include <boost/unordered/concurrent_flat_map_fwd.hpp>
#include <variant>
namespace nix {
@ -507,13 +507,23 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut
*/
std::map<std::string, Hash> staticOutputHashes(Store & store, const Derivation & drv);
struct DrvHashFct
{
using is_avalanching = std::true_type;
std::size_t operator()(const StorePath & path) const noexcept
{
return std::hash<std::string_view>{}(path.to_string());
}
};
/**
* Memoisation of hashDerivationModulo().
*/
typedef std::map<StorePath, DrvHash> DrvHashes;
typedef boost::concurrent_flat_map<StorePath, DrvHash, DrvHashFct> DrvHashes;
// FIXME: global, though at least thread-safe.
extern Sync<DrvHashes> drvHashes;
extern DrvHashes drvHashes;
struct Source;
struct Sink;

View file

@ -1,13 +1,17 @@
#pragma once
///@file
#include <unordered_set>
#include "nix/store/store-api.hh"
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/unordered_flat_set.hpp>
namespace nix {
typedef std::unordered_map<StorePath, std::unordered_set<std::string>> Roots;
typedef boost::unordered_flat_map<
StorePath,
boost::unordered_flat_set<std::string, StringViewHash, std::equal_to<>>,
std::hash<StorePath>>
Roots;
struct GCOptions
{

View file

@ -11,7 +11,7 @@
#include <chrono>
#include <future>
#include <string>
#include <unordered_set>
#include <boost/unordered/unordered_flat_set.hpp>
namespace nix {
@ -442,7 +442,7 @@ private:
std::pair<std::filesystem::path, AutoCloseFD> createTempDirInStore();
typedef std::unordered_set<ino_t> InodeHash;
typedef boost::unordered_flat_set<ino_t> InodeHash;
InodeHash loadInodeHash();
Strings readDirectoryIgnoringInodes(const Path & path, const InodeHash & inodeHash);

View file

@ -1,5 +1,3 @@
#include <unordered_set>
#include "nix/store/derivations.hh"
#include "nix/store/parsed-derivations.hh"
#include "nix/store/derivation-options.hh"
@ -13,6 +11,8 @@
#include "nix/store/filetransfer.hh"
#include "nix/util/strings.hh"
#include <boost/unordered/unordered_flat_set.hpp>
namespace nix {
void Store::computeFSClosure(
@ -106,7 +106,7 @@ MissingPaths Store::queryMissing(const std::vector<DerivedPath> & targets)
struct State
{
std::unordered_set<std::string> done;
boost::unordered_flat_set<std::string> done;
MissingPaths res;
};