Core/Misc: Optimized ByteBuffer::ReadString

This commit is contained in:
Shauren
2014-10-23 18:11:42 +02:00
parent 08c56eb110
commit 2f36898409

View File

@@ -498,13 +498,16 @@ class ByteBuffer
std::string ReadString(uint32 length)
{
if (_rpos + length > size())
throw ByteBufferPositionException(false, _rpos, length, size());
if (!length)
return std::string();
char* buffer = new char[length + 1];
read((uint8*)buffer, length);
std::string retval = buffer;
delete[] buffer;
return retval;
ResetBitPos();
std::string str((char const*)&_storage[_rpos], length);
_rpos += length;
return str;
}
//! Method for writing strings that have their length sent separately in packet