diff options
author | Max Kellermann <max@musicpd.org> | 2020-10-30 16:22:59 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-10-30 16:25:41 +0100 |
commit | b9b02b4ff202e0b30255c002b85d363efd5715c6 (patch) | |
tree | ccd31106aecafe3e4530e00baf594aa4d9daf85e /src | |
parent | ab5d23da1106c16e366f9e278478f7bdca0d01d5 (diff) |
event/PollBackend: use unordered_map::find() instead of operator[]
The latter creates a new object, but we know that the key already
exists.
Diffstat (limited to 'src')
-rw-r--r-- | src/event/PollBackend.cxx | 8 |
1 files changed, 6 insertions, 2 deletions
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; } } |