Commit 36c42004 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Canonical impl of futures Core::removeStaleDependents

Summary: [Folly] Canonical impl of futures `Core::removeStaleDependents` using std algorithms.

Reviewed By: leikahing, igorsugak

Differential Revision: D19167292

fbshipit-source-id: 702fdf07bdcc295ed990d2c02cd3380ea81694a2
parent 576eeaee
...@@ -171,15 +171,9 @@ void Core::addDependent(Core::WeakPtr dependent) { ...@@ -171,15 +171,9 @@ void Core::addDependent(Core::WeakPtr dependent) {
void Core::removeStaleDependents() { void Core::removeStaleDependents() {
// This is inefficient, the assumption is that we won't have many dependents // This is inefficient, the assumption is that we won't have many dependents
dependents_.withWLock([](Dependents& dependents) { dependents_.withWLock([](Dependents& deps) {
for (size_t i = 0; i < dependents.size();) { auto const pred = [](auto const& d) { return d.expired(); };
if (dependents[i].expired()) { deps.erase(std::remove_if(deps.begin(), deps.end(), pred), deps.end());
std::swap(dependents[i], dependents.back());
dependents.pop_back();
} else {
++i;
}
}
}); });
} }
} // namespace observer_detail } // namespace observer_detail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment