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) {
void Core::removeStaleDependents() {
// This is inefficient, the assumption is that we won't have many dependents
dependents_.withWLock([](Dependents& dependents) {
for (size_t i = 0; i < dependents.size();) {
if (dependents[i].expired()) {
std::swap(dependents[i], dependents.back());
dependents.pop_back();
} else {
++i;
}
}
dependents_.withWLock([](Dependents& deps) {
auto const pred = [](auto const& d) { return d.expired(); };
deps.erase(std::remove_if(deps.begin(), deps.end(), pred), deps.end());
});
}
} // 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