From 6bd2c7bb386de16310fa5534275e6e638be60862 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 17 Jul 2015 19:24:28 +0200 Subject: OCD: foreach -> C++11 ranged for --- src/libstore/gc.cc | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/libstore/gc.cc') diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 8d7da67f5204..998a7516a13d 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -350,15 +350,14 @@ static void addAdditionalRoots(StoreAPI & store, PathSet & roots) StringSet paths = tokenizeString(result, "\n"); - foreach (StringSet::iterator, i, paths) { - if (isInStore(*i)) { - Path path = toStorePath(*i); + for (auto & i : paths) + if (isInStore(i)) { + Path path = toStorePath(i); if (roots.find(path) == roots.end() && store.isValidPath(path)) { debug(format("got additional root ‘%1%’") % path); roots.insert(path); } } - } } @@ -408,8 +407,8 @@ void LocalStore::deletePathRecursive(GCState & state, const Path & path) if (isValidPath(path)) { PathSet referrers; queryReferrers(path, referrers); - foreach (PathSet::iterator, i, referrers) - if (*i != path) deletePathRecursive(state, *i); + for (auto & i : referrers) + if (i != path) deletePathRecursive(state, i); size = queryPathInfo(path).narSize; invalidatePathChecked(path); } @@ -487,22 +486,22 @@ bool LocalStore::canReachRoot(GCState & state, PathSet & visited, const Path & p don't delete the derivation if any of the outputs are alive. */ if (state.gcKeepDerivations && isDerivation(path)) { PathSet outputs = queryDerivationOutputs(path); - foreach (PathSet::iterator, i, outputs) - if (isValidPath(*i) && queryDeriver(*i) == path) - incoming.insert(*i); + for (auto & i : outputs) + if (isValidPath(i) && queryDeriver(i) == path) + incoming.insert(i); } /* If gc-keep-outputs is set, then don't delete this path if there are derivers of this path that are not garbage. */ if (state.gcKeepOutputs) { PathSet derivers = queryValidDerivers(path); - foreach (PathSet::iterator, i, derivers) - incoming.insert(*i); + for (auto & i : derivers) + incoming.insert(i); } - foreach (PathSet::iterator, i, incoming) - if (*i != path) - if (canReachRoot(state, visited, *i)) { + for (auto & i : incoming) + if (i != path) + if (canReachRoot(state, visited, i)) { state.alive.insert(path); return true; } @@ -622,7 +621,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) printMsg(lvlError, format("finding garbage collector roots...")); Roots rootMap = options.ignoreLiveness ? Roots() : findRoots(); - foreach (Roots::iterator, i, rootMap) state.roots.insert(i->second); + for (auto & i : rootMap) state.roots.insert(i.second); /* Add additional roots returned by the program specified by the NIX_ROOT_FINDER environment variable. This is typically used @@ -659,11 +658,11 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) if (options.action == GCOptions::gcDeleteSpecific) { - foreach (PathSet::iterator, i, options.pathsToDelete) { - assertStorePath(*i); - tryToDelete(state, *i); - if (state.dead.find(*i) == state.dead.end()) - throw Error(format("cannot delete path ‘%1%’ since it is still alive") % *i); + for (auto & i : options.pathsToDelete) { + assertStorePath(i); + tryToDelete(state, i); + if (state.dead.find(i) == state.dead.end()) + throw Error(format("cannot delete path ‘%1%’ since it is still alive") % i); } } else if (options.maxFreed > 0) { @@ -707,8 +706,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) vector entries_(entries.begin(), entries.end()); random_shuffle(entries_.begin(), entries_.end()); - foreach (vector::iterator, i, entries_) - tryToDelete(state, *i); + for (auto & i : entries_) + tryToDelete(state, i); } catch (GCLimitReached & e) { } -- cgit 1.4.1