From: Arnaud Giersch Date: Tue, 25 May 2021 14:58:42 +0000 (+0200) Subject: Lookup only once on mailbox creation. X-Git-Tag: v3.28~231 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ba24a6c5ee07011c4418b2e327843f0d62658157 Lookup only once on mailbox creation. --- diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index f664690b5c..6cdb27598a 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -247,14 +247,13 @@ Mailbox* Engine::mailbox_by_name_or_create(const std::string& name) const { /* two actors may have pushed the same mbox_create simcall at the same time */ kernel::activity::MailboxImpl* mbox = kernel::actor::simcall([&name, this] { - auto m = pimpl->mailboxes_.find(name); - if (m == pimpl->mailboxes_.end()) { + auto m = pimpl->mailboxes_.emplace(name, nullptr); + if (m.second) { auto* mbox = new kernel::activity::MailboxImpl(name); XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name.c_str()); - pimpl->mailboxes_[name] = mbox; - return mbox; - } else - return m->second; + m.first->second = mbox; + } + return m.first->second; }); return mbox->get_iface(); }