|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r49198 - trunk/boost/asio
From: chris_at_[hidden]
Date: 2008-10-09 02:30:17
Author: chris_kohlhoff
Date: 2008-10-09 02:30:16 EDT (Thu, 09 Oct 2008)
New Revision: 49198
URL: http://svn.boost.org/trac/boost/changeset/49198
Log:
Ensure the streambuf's egptr() is kept in sync the pptr(). Use std::memmove
rather than std::rotate to minimise data copying. Avoid unnecessary resizes
of the underlying vector.
Text files modified:
trunk/boost/asio/basic_streambuf.hpp | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
Modified: trunk/boost/asio/basic_streambuf.hpp
==============================================================================
--- trunk/boost/asio/basic_streambuf.hpp (original)
+++ trunk/boost/asio/basic_streambuf.hpp 2008-10-09 02:30:16 EDT (Thu, 09 Oct 2008)
@@ -19,6 +19,7 @@
#include <boost/asio/detail/push_options.hpp>
#include <algorithm>
+#include <cstring>
#include <limits>
#include <memory>
#include <stdexcept>
@@ -96,6 +97,7 @@
if (pptr() + n > epptr())
n = epptr() - pptr();
pbump(static_cast<int>(n));
+ setg(eback(), gptr(), pptr());
}
/// Move the start of the get area by the specified number of characters.
@@ -151,7 +153,6 @@
{
// Get current stream positions as offsets.
std::size_t gnext = gptr() - &buffer_[0];
- std::size_t gend = egptr() - &buffer_[0];
std::size_t pnext = pptr() - &buffer_[0];
std::size_t pend = epptr() - &buffer_[0];
@@ -164,9 +165,8 @@
// Shift existing contents of get area to start of buffer.
if (gnext > 0)
{
- std::rotate(&buffer_[0], &buffer_[0] + gnext, &buffer_[0] + pend);
- gend -= gnext;
pnext -= gnext;
+ std::memmove(&buffer_[0], &buffer_[0] + gnext, pnext);
}
// Ensure buffer is large enough to hold at least the specified size.
@@ -174,7 +174,8 @@
{
if (n <= max_size_ && pnext <= max_size_ - n)
{
- buffer_.resize((std::max<std::size_t>)(pnext + n, 1));
+ pend = pnext + n;
+ buffer_.resize((std::max<std::size_t>)(pend, 1));
}
else
{
@@ -183,8 +184,8 @@
}
// Update stream positions.
- setg(&buffer_[0], &buffer_[0], &buffer_[0] + gend);
- setp(&buffer_[0] + pnext, &buffer_[0] + pnext + n);
+ setg(&buffer_[0], &buffer_[0], &buffer_[0] + pnext);
+ setp(&buffer_[0] + pnext, &buffer_[0] + pend);
}
private:
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk