Commit aa425522 authored by louiz’'s avatar louiz’

Optimize tcp_socket::on_send by using vector::erase() only once per call

parent ce06c25e
...@@ -305,23 +305,24 @@ void TCPSocketHandler::on_send() ...@@ -305,23 +305,24 @@ void TCPSocketHandler::on_send()
else else
{ {
// remove all the strings that were successfully sent. // remove all the strings that were successfully sent.
for (auto it = this->out_buf.begin(); auto it = this->out_buf.begin();
it != this->out_buf.end();) while (it != this->out_buf.end())
{ {
if (static_cast<size_t>(res) >= (*it).size()) if (static_cast<size_t>(res) >= it->size())
{ {
res -= (*it).size(); res -= it->size();
it = this->out_buf.erase(it); ++it;
} }
else else
{ {
// If one string has partially been sent, we use substr to // If one string has partially been sent, we use substr to
// crop it // crop it
if (res > 0) if (res > 0)
(*it) = (*it).substr(res, std::string::npos); *it = it->substr(res, std::string::npos);
break; break;
} }
} }
this->out_buf.erase(this->out_buf.begin(), it);
if (this->out_buf.empty()) if (this->out_buf.empty())
this->poller->stop_watching_send_events(this); this->poller->stop_watching_send_events(this);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment