avoid copy in BinaryReader::readString(size_t length)

This commit is contained in:
Martchus 2016-02-20 01:35:42 +01:00
parent 7e780d647a
commit 3d510a0682
1 changed files with 4 additions and 9 deletions

View File

@ -125,15 +125,10 @@ string BinaryReader::readLengthPrefixedString()
*/
string BinaryReader::readString(size_t length)
{
//string res;
//res.reserve(length);
//for(; length; --length) {
// res.push_back(static_cast<string::value_type>(m_stream->get()));
//}
//return res;
unique_ptr<char []> buff = make_unique<char []>(length);
m_stream->read(buff.get(), length);
return string(buff.get(), length);
string res;
res.resize(length);
m_stream->read(&res[0], length);
return res;
}
/*!