summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-10-20 20:08:29 +0200
committerlouiz’ <louiz@louiz.org>2016-10-20 20:08:29 +0200
commitaa4255224eb19ca55a963574fb527e1f07ff9cba (patch)
treefe59c0178dc07e482f53c1c630ad5b51fc02b0bb
parentce06c25e93183282be42ab79bfed2ab7c02791ec (diff)
downloadbiboumi-aa4255224eb19ca55a963574fb527e1f07ff9cba.tar.gz
biboumi-aa4255224eb19ca55a963574fb527e1f07ff9cba.tar.bz2
biboumi-aa4255224eb19ca55a963574fb527e1f07ff9cba.tar.xz
biboumi-aa4255224eb19ca55a963574fb527e1f07ff9cba.zip
Optimize tcp_socket::on_send by using vector::erase() only once per call
-rw-r--r--louloulibs/network/tcp_socket_handler.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp
index ca267cd..9d8cfea 100644
--- a/louloulibs/network/tcp_socket_handler.cpp
+++ b/louloulibs/network/tcp_socket_handler.cpp
@@ -305,23 +305,24 @@ void TCPSocketHandler::on_send()
else
{
// remove all the strings that were successfully sent.
- for (auto it = this->out_buf.begin();
- it != this->out_buf.end();)
+ auto it = this->out_buf.begin();
+ 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();
- it = this->out_buf.erase(it);
+ res -= it->size();
+ ++it;
}
else
{
// If one string has partially been sent, we use substr to
// crop it
if (res > 0)
- (*it) = (*it).substr(res, std::string::npos);
+ *it = it->substr(res, std::string::npos);
break;
}
}
+ this->out_buf.erase(this->out_buf.begin(), it);
if (this->out_buf.empty())
this->poller->stop_watching_send_events(this);
}