Use boost array sink to avoid copying buffer for BufferReader

This commit is contained in:
Patrick Niklaus 2018-03-26 14:23:52 +00:00 committed by Patrick Niklaus
parent 5395290fd5
commit 81929c984b

View File

@ -12,6 +12,8 @@
#include <boost/filesystem/fstream.hpp>
#include <boost/iostreams/seek.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/array.hpp>
#include <cerrno>
#include <cstring>
@ -294,7 +296,11 @@ class FileWriter
class BufferReader
{
public:
BufferReader(const std::string &buffer) : input_stream(buffer, std::ios::binary)
BufferReader(const std::string &buffer) : BufferReader(buffer.data(), buffer.size())
{
}
BufferReader(const char* buffer, const std::size_t size) : input_stream(boost::iostreams::array_source(buffer, size))
{
if (!input_stream)
{
@ -342,7 +348,7 @@ class BufferReader
}
private:
std::istringstream input_stream;
boost::iostreams::stream<boost::iostreams::array_source> input_stream;
};
class BufferWriter