refactor: omit redundant map searches (#19929)

* refactor: don't walk maps twice to remove elements

* refactor: don't walk maps twice to read elements

* refactor: don't walk maps twice to insert elements

* refactor: don't walk map 3x on UvTaskRunner timeout

* refactor: more don't-walk-maps-twice cleanup

* fixup! refactor: don't walk maps twice to insert elements

* refactor: don't walk containers twice when erasing

* refactor: omit excess lookups in RemoteObjectFreer
This commit is contained in:
Charles Kerr
2019-08-28 09:39:21 -05:00
committed by GitHub
parent 27ce6a9cd3
commit 987300c97a
14 changed files with 88 additions and 86 deletions

View File

@@ -42,12 +42,13 @@ bool UvTaskRunner::PostNonNestableDelayedTask(const base::Location& from_here,
// static
void UvTaskRunner::OnTimeout(uv_timer_t* timer) {
UvTaskRunner* self = static_cast<UvTaskRunner*>(timer->data);
if (!base::Contains(self->tasks_, timer))
auto& tasks = static_cast<UvTaskRunner*>(timer->data)->tasks_;
const auto iter = tasks.find(timer);
if (iter == std::end(tasks))
return;
std::move(self->tasks_[timer]).Run();
self->tasks_.erase(timer);
std::move(iter->second).Run();
tasks.erase(iter);
uv_timer_stop(timer);
uv_close(reinterpret_cast<uv_handle_t*>(timer), UvTaskRunner::OnClose);
}