diff options
author | Max Kellermann <max@musicpd.org> | 2020-10-30 15:30:11 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-10-30 15:32:11 +0100 |
commit | fee29001fa4fad6da9e15df73c47452e17e80c8a (patch) | |
tree | f45ab986e4eb8985f3b46fda9c273d6bf82b749f /src | |
parent | 6d894a1806629d911d9c6caca6442b504988bb3b (diff) |
event/WinSelect: use unordered_map::emplace() in Add()
This allow using erase() with iterator, without a key lookup.
Diffstat (limited to 'src')
-rw-r--r-- | src/event/WinSelectBackend.cxx | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/event/WinSelectBackend.cxx b/src/event/WinSelectBackend.cxx index e8d7ab12d..4e919a85e 100644 --- a/src/event/WinSelectBackend.cxx +++ b/src/event/WinSelectBackend.cxx @@ -64,7 +64,8 @@ bool WinSelectBackend::Add(SOCKET fd, unsigned events, void *obj) noexcept { assert(items.find(fd) == items.end()); - auto &item = items[fd]; + auto i = items.emplace(fd, Item{}).first; + auto &item = i->second; item.index[EVENT_READ] = -1; item.index[EVENT_WRITE] = -1; @@ -72,11 +73,11 @@ WinSelectBackend::Add(SOCKET fd, unsigned events, void *obj) noexcept item.events = 0; if (!CanModify(item, events, EVENT_READ)) { - items.erase(fd); + items.erase(i); return false; } if (!CanModify(item, events, EVENT_WRITE)) { - items.erase(fd); + items.erase(i); return false; } |