Browse Source

eliminate extra copy

pull/73/merge
orignal 11 years ago
parent
commit
acbe0d801d
  1. 7
      TunnelGateway.cpp
  2. 5
      TunnelGateway.h

7
TunnelGateway.cpp

@ -107,12 +107,9 @@ namespace tunnel
} }
} }
const std::vector<I2NPMessage *> TunnelGatewayBuffer::GetTunnelDataMsgs () void TunnelGatewayBuffer::ClearTunnelDataMsgs ()
{ {
CompleteCurrentTunnelDataMessage ();
std::vector<I2NPMessage *> ret = m_TunnelDataMsgs; // TODO: implement it better
m_TunnelDataMsgs.clear (); m_TunnelDataMsgs.clear ();
return ret;
} }
void TunnelGatewayBuffer::CreateCurrentTunnelDataMessage () void TunnelGatewayBuffer::CreateCurrentTunnelDataMessage ()
@ -162,6 +159,7 @@ namespace tunnel
void TunnelGateway::SendBuffer () void TunnelGateway::SendBuffer ()
{ {
m_Buffer.CompleteCurrentTunnelDataMessage ();
auto tunnelMsgs = m_Buffer.GetTunnelDataMsgs (); auto tunnelMsgs = m_Buffer.GetTunnelDataMsgs ();
for (auto tunnelMsg : tunnelMsgs) for (auto tunnelMsg : tunnelMsgs)
{ {
@ -170,6 +168,7 @@ namespace tunnel
i2p::transports.SendMessage (m_Tunnel->GetNextIdentHash (), tunnelMsg); i2p::transports.SendMessage (m_Tunnel->GetNextIdentHash (), tunnelMsg);
m_NumSentBytes += TUNNEL_DATA_MSG_SIZE; m_NumSentBytes += TUNNEL_DATA_MSG_SIZE;
} }
m_Buffer.ClearTunnelDataMsgs ();
} }
} }
} }

5
TunnelGateway.h

@ -16,12 +16,13 @@ namespace tunnel
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID), TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID),
m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {}; m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {};
void PutI2NPMsg (const TunnelMessageBlock& block); void PutI2NPMsg (const TunnelMessageBlock& block);
const std::vector<I2NPMessage *> GetTunnelDataMsgs (); const std::vector<I2NPMessage *>& GetTunnelDataMsgs () const { return m_TunnelDataMsgs; };
void ClearTunnelDataMsgs ();
void CompleteCurrentTunnelDataMessage ();
private: private:
void CreateCurrentTunnelDataMessage (); void CreateCurrentTunnelDataMessage ();
void CompleteCurrentTunnelDataMessage ();
private: private:

Loading…
Cancel
Save