From fee29001fa4fad6da9e15df73c47452e17e80c8a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 30 Oct 2020 15:30:11 +0100 Subject: [PATCH] event/WinSelect: use unordered_map::emplace() in Add() This allow using erase() with iterator, without a key lookup. --- src/event/WinSelectBackend.cxx | 7 ++++--- 1 file 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; }