From b9b02b4ff202e0b30255c002b85d363efd5715c6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 30 Oct 2020 16:22:59 +0100 Subject: event/PollBackend: use unordered_map::find() instead of operator[] The latter creates a new object, but we know that the key already exists. --- src/event/PollBackend.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/event/PollBackend.cxx b/src/event/PollBackend.cxx index a505816d0..74345a745 100644 --- a/src/event/PollBackend.cxx +++ b/src/event/PollBackend.cxx @@ -66,7 +66,7 @@ PollBackend::Remove(int fd) noexcept std::size_t last_index = poll_events.size() - 1; if (index != last_index) { std::swap(poll_events[index], poll_events[last_index]); - items[poll_events[index].fd].index = index; + items.find(poll_events[index].fd)->second.index = index; } poll_events.pop_back(); items.erase(item_iter); @@ -83,7 +83,11 @@ PollBackend::ReadEvents(int timeout_ms) noexcept for (std::size_t i = 0; n > 0 && i < poll_events.size(); ++i) { const auto &e = poll_events[i]; if (e.revents != 0) { - result.Add(e.revents, items[e.fd].obj); + auto it = items.find(e.fd); + assert(it != items.end()); + assert(it->second.index == i); + + result.Add(e.revents, it->second.obj); --n; } } -- cgit v1.2.3