mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 01:39:36 +01:00
OCD performance fix: {find,count}+insert => insert
This commit is contained in:
parent
e6e61f0a54
commit
99b73fb507
16 changed files with 32 additions and 65 deletions
|
|
@ -568,10 +568,9 @@ UserLock::UserLock()
|
|||
|
||||
{
|
||||
auto lockedPaths(lockedPaths_.lock());
|
||||
if (lockedPaths->count(fnUserLock))
|
||||
if (!lockedPaths->insert(fnUserLock).second)
|
||||
/* We already have a lock on this one. */
|
||||
continue;
|
||||
lockedPaths->insert(fnUserLock);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -620,8 +619,8 @@ UserLock::UserLock()
|
|||
UserLock::~UserLock()
|
||||
{
|
||||
auto lockedPaths(lockedPaths_.lock());
|
||||
assert(lockedPaths->count(fnUserLock));
|
||||
lockedPaths->erase(fnUserLock);
|
||||
auto erased = lockedPaths->erase(fnUserLock);
|
||||
assert(erased);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1125,10 +1124,8 @@ void DerivationGoal::addWantedOutputs(const StringSet & outputs)
|
|||
needRestart = true;
|
||||
} else
|
||||
for (auto & i : outputs)
|
||||
if (wantedOutputs.find(i) == wantedOutputs.end()) {
|
||||
wantedOutputs.insert(i);
|
||||
if (wantedOutputs.insert(i).second)
|
||||
needRestart = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -123,8 +123,7 @@ static Path out;
|
|||
|
||||
static void addPkg(const Path & pkgDir, int priority)
|
||||
{
|
||||
if (done.count(pkgDir)) return;
|
||||
done.insert(pkgDir);
|
||||
if (!done.insert(pkgDir).second) return;
|
||||
createLinks(pkgDir, out, priority);
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1292,8 +1292,7 @@ void LocalStore::verifyPath(const Path & path, const PathSet & store,
|
|||
{
|
||||
checkInterrupt();
|
||||
|
||||
if (done.find(path) != done.end()) return;
|
||||
done.insert(path);
|
||||
if (!done.insert(path).second) return;
|
||||
|
||||
if (!isStorePath(path)) {
|
||||
printError(format("path '%1%' is not in the Nix store") % path);
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ void Store::computeFSClosure(const PathSet & startPaths,
|
|||
{
|
||||
auto state(state_.lock());
|
||||
if (state->exc) return;
|
||||
if (state->paths.count(path)) return;
|
||||
state->paths.insert(path);
|
||||
if (!state->paths.insert(path).second) return;
|
||||
state->pending++;
|
||||
}
|
||||
|
||||
|
|
@ -175,8 +174,7 @@ void Store::queryMissing(const PathSet & targets,
|
|||
|
||||
{
|
||||
auto state(state_.lock());
|
||||
if (state->done.count(path)) return;
|
||||
state->done.insert(path);
|
||||
if (!state->done.insert(path).second) return;
|
||||
}
|
||||
|
||||
DrvPathWithOutputs i2 = parseDrvPathWithOutputs(path);
|
||||
|
|
@ -252,8 +250,7 @@ Paths Store::topoSortPaths(const PathSet & paths)
|
|||
if (parents.find(path) != parents.end())
|
||||
throw BuildError(format("cycle detected in the references of '%1%' from '%2%'") % path % *parent);
|
||||
|
||||
if (visited.find(path) != visited.end()) return;
|
||||
visited.insert(path);
|
||||
if (!visited.insert(path).second) return;
|
||||
parents.insert(path);
|
||||
|
||||
PathSet references;
|
||||
|
|
|
|||
|
|
@ -36,11 +36,10 @@ static void search(const unsigned char * s, size_t len,
|
|||
}
|
||||
if (!match) continue;
|
||||
string ref((const char *) s + i, refLength);
|
||||
if (hashes.find(ref) != hashes.end()) {
|
||||
if (hashes.erase(ref)) {
|
||||
debug(format("found reference to '%1%' at offset '%2%'")
|
||||
% ref % i);
|
||||
seen.insert(ref);
|
||||
hashes.erase(ref);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -954,8 +954,7 @@ std::list<ref<Store>> getDefaultSubstituters()
|
|||
StringSet done;
|
||||
|
||||
auto addStore = [&](const std::string & uri) {
|
||||
if (done.count(uri)) return;
|
||||
done.insert(uri);
|
||||
if (!done.insert(uri).second) return;
|
||||
try {
|
||||
stores.push_back(openStore(uri));
|
||||
} catch (Error & e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue