use flat_map for smaller tables

This commit is contained in:
orignal 2021-09-24 14:23:39 -04:00
parent 18b6ba80f2
commit 518e53a61c
4 changed files with 7 additions and 7 deletions

View File

@ -218,7 +218,7 @@ namespace transport
void SSUServer::AddRelay (uint32_t tag, std::shared_ptr<SSUSession> relay)
{
m_Relays[tag] = relay;
m_Relays.emplace (tag, relay);
}
void SSUServer::RemoveRelay (uint32_t tag)

View File

@ -139,7 +139,7 @@ namespace transport
std::list<boost::asio::ip::udp::endpoint> m_Introducers, m_IntroducersV6; // introducers we are connected to
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > m_Sessions, m_SessionsV6;
std::map<uint32_t, std::shared_ptr<SSUSession> > m_Relays; // we are introducer
std::map<uint32_t, PeerTest> m_PeerTests; // nonce -> creation time in milliseconds
boost::container::flat_map<uint32_t, PeerTest> m_PeerTests; // nonce -> creation time in milliseconds
i2p::util::MemoryPool<Fragment> m_FragmentsPool;
i2p::util::MemoryPool<IncompleteMessage> m_IncompleteMessagesPool;

View File

@ -310,7 +310,7 @@ namespace transport
if (m_SentMessages.empty ()) // schedule resend at first message only
ScheduleResend ();
auto ret = m_SentMessages.insert (std::make_pair (msgID, m_Session.GetServer ().GetSentMessagesPool ().AcquireShared ()));
auto ret = m_SentMessages.emplace (msgID, m_Session.GetServer ().GetSentMessagesPool ().AcquireShared ());
auto& sentMessage = ret.first->second;
if (ret.second)
{

View File

@ -11,10 +11,10 @@
#include <inttypes.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#include <memory>
#include <boost/asio.hpp>
#include <boost/container/flat_map.hpp>
#include "I2NPProtocol.h"
#include "Identity.h"
#include "RouterInfo.h"
@ -123,9 +123,9 @@ namespace transport
private:
SSUSession& m_Session;
std::unordered_map<uint32_t, std::shared_ptr<IncompleteMessage> > m_IncompleteMessages;
std::unordered_map<uint32_t, std::shared_ptr<SentMessage> > m_SentMessages;
std::unordered_map<uint32_t, uint64_t> m_ReceivedMessages; // msgID -> timestamp in seconds
boost::container::flat_map<uint32_t, std::shared_ptr<IncompleteMessage> > m_IncompleteMessages;
boost::container::flat_map<uint32_t, std::shared_ptr<SentMessage> > m_SentMessages;
boost::container::flat_map<uint32_t, uint64_t> m_ReceivedMessages; // msgID -> timestamp in seconds
boost::asio::deadline_timer m_ResendTimer;
int m_MaxPacketSize, m_PacketSize;
i2p::I2NPMessagesHandler m_Handler;